Home | About | Apps | Github | Rss

Discarding changs in git and submodules

git master repo

To discard local changes in git repository

	git reset --hard

submodule repo

For submodules its a bit tricky.

 git submodule update --init
 git submodule foreach git reset --hard

If none of it works

It probably means there are some hidden/gitignored files lying around in submodule repository directory. For example, I was seeing this and none of the above steps helped.

kalyan@pogobook:project$ git status
# 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)
#   (commit or discard the untracked or modified content in submodules)
#
#	modified:   ReactiveCocoa (untracked content)
#

kalyan@pogobook$ git diff
diff --git a/ReactiveCocoa b/ReactiveCocoa
--- a/ReactiveCocoa
+++ b/ReactiveCocoa
@@ -1 +1 @@
-Subproject commit 6ce5f58a0545c69039f262eb3b08c0e0a0c2c413
+Subproject commit 6ce5f58a0545c69039f262eb3b08c0e0a0c2c413-dirty

I went ahead and inspected what was inside the ReactiveCocoa directory

kalyan@pogobook:project$ cd ReactiveCocoa/
kalyan@pogobook:ReactiveCocoa$ git status
# Not currently on any branch.
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#	.DS_Store

Turns out .DS_Store was the culprit. Deleting it fixed the annoying untracked content message right away.

kalyan@pogobook:ReactiveCocoa$ rm .DS_Store 
kalyan@pogobook:ReactiveCocoa$ cd ..
kalyan@pogobook:project$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 2 commits.
#

More posts