Darragh
Darragh

Reputation: 119

Git How to discard changes to a submodule

I did some work in a git repository X, that has a submodule Y. I did some changes to files in X, which I want to keep and I did a change in the submodule Y that I want to discard now. So I want to discard all local changes I've made to the submodule.

I tried git checkout -- ../dep/libY but nothing changes.

Git status says:

modified:   ../dep/libY (modified content)

Upvotes: 4

Views: 8468

Answers (3)

IMParasharG
IMParasharG

Reputation: 1905

If you want to undo the changes, git checkout submodule

git checkout dep/libY

OR

Go to the folder (for which you want to revert all changes) and execute

git checkout ./ 

Upvotes: 1

kk.
kk.

Reputation: 3945

In your checked out directory execute this command which will reset the files changed in that sub-directory to HEAD revision (in short it will discard your uncommitted changes in that submodule/subdirectory)

git checkout HEAD -- path/to/submodule

In your case the command would be:

git checkout HEAD -- ../dep/libY 

Upvotes: 1

torek
torek

Reputation: 489848

A submodule is a Git repository. You may therefore cd into the submodule, and use git reset --hard to discard work done within the work-tree and index of that other Git repository. (Be sure to run git status in that work-tree first, and other Git commands, if / as desired to make sure that any files you are discarding are truly unwanted.)

Upvotes: 4

Related Questions