I have a git submodule in my main git repo. As I understand it, the main repo stores a SHA value (somewhere…), pointing to the specific commit of the submodule that it is “linked to”.
I went in to my submodule and typed git checkout some_other_branch. I have no idea which commit I came from.
I would like to revert that pointer so that the main repo and the submodule are in sync again.
My first (probably naive) instinct was to say git reset –hard – that seems to work for everything else. To my surprise, it did not work for this scenario.
So I’ve figured out that I can type git diff, note the SHA ID that the submodule pointer used to have, and then head into the submodule and git checkout [SHA ID]… but surely there must be an easier way?
As I’m still learning about git submodules, please feel free to correct my terminology if there are words for concepts that I don’t know.
Revert to pre-git v1.7.8 git submodule behavior with submodule filesystem locations
Recently in git 1.7.8, a change was introduced to handle submodules differently than before – https://lkml.org/lkml/2011/12/2/316 When populating a new submodule directory with git submodule init
Reverting a submodule with Git
I did git submodule add git://github.com/msanders/snipmate.vim.git bundle/snipmate and then I deleted the directory. How do I revert it? How do I revert files within it?
How do I revert my changes to a git submodule?
I have a git submodule (RestKit) which I have added to my repo. I accidentally changed some files in there and I’d like to go back to the source version. In order to do that, I tried to run Mac:app-i
Git update submodule recursive
My project struture ProjectA -FrameworkA (submodule) –Twig (submodule of FrameworkA) How I can update submodule recursive? I already tried some git commands (on ProjectA root) git submodule foreach
git submodule push?
I changed code in submodule and want to share with other team members. (Wow git submodule is hard) > cd to submodule > git add/commit > git push prompts me Username: and Password: > Userna
Git submodule: Move submodule outside repository
after creating a git submodule by typing git submodule add <repo> && git submodule init my .git/config is changed, as well as a new file .gitmodules is created. It seems that I would be
git revert and git checkout
Are the following combinations of commands equivalent? Combo #1: git revert HEAD git revert HEAD Combo #2: git revert HEAD git checkout HEAD^ git commit Related thread: Git cancel a revert
un-submodule a git submodule
How do I un-submodule a git submodule (bring all the code back into the core) ? As in how should I, as in Best procedure …
“git submodule” comes back empty
i use the following sequence to initialize and update git submodules: git init git submodule init git submodule update Then I want to see all the submodules, by this command: git submodule It prints
Bash: Git submodule foreach?
I have sup aliased to submodule foreach ‘git co master; git up’ (co & up are aliases for checkout & pull –rebase, respectively.). How do add a condition so that if the submodule name is Libra
To change the commit that a submodule points to, you need to checkout that version in the submodule, then go back to the containing repo, add and commit that change.
Or, if you want the submodule to be on the version the top repo points to, do git submodule update –recursive. Add –init if you’ve just cloned.
Also, git submodule without a submodule command will show you the commit you are pointing to. There will be a – or a + in front of the commit if it’s not in sync.
If you look at a tree with a submodule in it, you can see that the submodule is marked as a commit as opposed to the rest that are blobs or trees.
to see what a particular commit points wrt to submodules you can:
git ls-tree <some sha1, or branch, etc> Submodule/path
you can then see the commit or anything else if you like by passing that into log, etc (the git-dir option at the git command level allows you to skip having to cd down to the submodule):
git --git-dir=Submodule/path log -1 $(<the above statement>)
You want to update your submodule so it is in sync with what the parent repository believes it should be. This is what the update command is for:
From the submodule manpage:
Update the registered submodules, i.e. clone missing submodules and checkout the commit specified in the index of the containing repository. This will make the submodules HEAD be detached unless --rebase or --merge is specified or the key submodule.$name.update is set to rebase or merge.
Run this and all should be well:
git submodule update
Use git ls-tree HEAD in the “superproject” folder to see what commit your submodule was originally at. Then change into the submodule directory and use git log –oneline –decorate to see what branch the original commit is on. Finally, git checkout original-commit-branch.
Using some test directories I set up, here’s what the commands might look like:
$ git --version git version 18.104.22.168 $ git status # On branch master # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: sm2 (new commits) # no changes added to commit (use "git add" and/or "git commit -a") $ git ls-tree HEAD 100644 blob 76813a07ae558db274cefc6d903ec24323fdeb0d .gitmodules 100644 blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 main 160000 commit 7c5889497938cd5699a9234a98ee93947e52b1ed sm1 160000 commit f68bed61cba6f94cef57554f2cf46a45a4a0d337 sm2 $ cd sm2 $ git log --oneline --decorate 5b8d48f (HEAD, foo1) foo1.1 f68bed6 (origin/master, origin/HEAD, master) Initial commit. $ git checkout master Switched to branch 'master' $ cd .. $ git status # On branch master nothing to commit (working directory clean)
The “superproject” shows the sm2 submodule at commit f68bed6 but sm2 has it’s HEAD at 5b8d48f. The submodule commit f68bed6 has three branches on it that may be used for checkout in the submodule directory.