Git submodule point to branch8/10/2023 ![]() ![]() ![]() ![]() If you want to see what this looks like once pushed to remote (github. Git commit -amend -no-edit # I combined this with the previous commit where I added the 'branch' value in. So finally, I did what I was trying to avoid: git add You have to go and update that submodule commit reference to the latest code in the remote branch to avoid this Example either added with a branch to follow: git submodule -b abranch - /url/of/submodule/repo or configured (for an existing submodule) to follow a branch. So far, I was following the official git reference for submodules, now I decided to do some more Googling, and I stumbled an article titled Getting git submodule to track a branch, this clearly said Post this, when I ran git submodule update -remote -init -recursive, it would no longer revert my submodule's HEAD in detached state to commit A however it still kept showing the annoying modified: (new commits) So then I set the branch value as new-submodule-branch in /.gitmodules as follows If, from the main repo root, I ran git submodule update -remote -init -recursive, it kept reverting my submodule's HEAD in detached state to commit A Otherwise git submodule update -init -remote always make Git show module as modified if the branch gets updated upstream :( Cheers. " to discard changes in working directory) Post this, my main repo started showing Changes not staged for commit: Initially my submodule was at commit A (at the time of adding submodule to main repo), then I checked out a branch (let us call it new-submodule-branch) and made commits B and C to it and pushed it to remote () I am documenting/sharing here what worked for me. None of the answers here solve my problem. git submodule add -f -name coq- projects/metalib coq-projects/metalib. To update which commit records should be checked out for the submodule, you need to git commit the submodule in addition to committing the changes in the submodule: git add src/repo branch echo master echo main ) but obviously edited so it works with commits e.g. No changes added to commit (use "git add" and/or "git commit -a") (commit or discard the untracked or modified content in submodules) git status also claims submodule has untracked/modified content. Otherwise it shows -dirty hash change which you cannot stage or commit in the top-level repository. A branch name in a repository simply holds a commit hash ID. That will record an updated special entry of the index memorizing the new SHA1 for submodule xxx. +++ -1 +1 commit b0c86e28675c9591df51eedc928f991ca42f5fea Branches never point to branches: not within a repository, not across repositories. git add xxx git commit -m 'Updated submodule'. If you've already made some commits in your submodule (thus "clean" in submodule), it reports submodule's hash change. Run git diff in the top-level repository to show what has actually changed Git thinks. If you change something in submodule dir, Git will detect it and urge you to commit those changes in the top-level repoisitory. git commit -m 'Updating Submodule' That will make your branch 'point' at the correct commit. It's because Git records which commit (not a branch or a tag, exactly one commit represented in SHA-1 hash) should be checked out for each submodule. The initial clone of a submodule will use the recommended submodule.shallow as provided by the. either added with a branch to follow: git submodule -b abranch - /url/of/submodule/repo or configured (for an existing submodule) to follow a branch: cd /path/to/parent/repo git config -f. Instead of using the superproject’s recorded SHA-1 to update the submodule, use the status of the submodule’s remote-tracking branchĭon’t fetch new objects from the remote site This change in the parent repository should be committed if it’s to be used as a submodule in the future. Initialize all submodules for which 'git submodule init' has not been called so far before updating
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |