Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to discard change to git submodule?

I changed the commit pointer of a git submodule:

% git status
# On branch fix
# Your branch is behind 'origin/fix' by 1 commit, and can be fast-forwarded.
#
# 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:   app/lib (new commits)
#
no changes added to commit (use "git add" and/or "git commit -a")

Yet when I do git checkout, nothing changes:

% git checkout -- app/lib && git status
# On branch fix
# Your branch is behind 'origin/fix' by 1 commit, and can be fast-forwarded.
#
# 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:   app/lib (new commits)
#
no changes added to commit (use "git add" and/or "git commit -a")

Here's the diff:

% git diff
diff --git a/app/lib b/app/lib
index d670460..83baae6 160000
--- a/app/web-lib
+++ b/app/web-lib
@@ -1 +1 @@
-Subproject commit d670460b4b4aece5915caf5c68d12f560a9fe3e4
+Subproject commit 83baae61804e65cc73a7201a7252750c76066a30

Any idea why this happen?

Thanks!

like image 997
charlax Avatar asked Aug 30 '12 07:08

charlax


1 Answers

Git doesn't update submodules automatically when the SHA in them has changed.

You either need to git submodule update which will put the submodule back to the expected SHA, or git add app/lib which will change the expected SHA to the current value in the submodule.

like image 113
Michael Anderson Avatar answered Oct 14 '22 23:10

Michael Anderson