Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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-ios user$ git submodule update RestKit 

But as you can see here, this did not work as it is still "modified content":

Mac:app-ios user$ git status ... #   modified:   RestKit (modified content) 

Even

Mac:app-ios user$ git submodule update -f RestKit  

doesn't revert locally modified files.
How do I reset the content of that submodule?

like image 708
Eric Avatar asked Jun 05 '12 23:06

Eric


People also ask

Can you make changes to a git submodule?

The submodule is just a separate repository. If you want to make changes to it, you should make the changes in its repository and push them like in a regular Git repository (just execute the git commands in the submodule's directory).

How do you pull changes from submodules?

Once you have set up the submodules you can update the repository with fetch/pull like you would normally do. To pull everything including the submodules, use the --recurse-submodules and the --remote parameter in the git pull command .

How do you push changes to submodules?

Just cd into the submodule's directory and: git add -A git commit -m "some message" git push Then cd to the main repo and do the same.

How do I create a submodule from an existing repo?

In order to add a Git submodule, use the “git submodule add” command and specify the URL of the Git remote repository to be included as a submodule. When adding a Git submodule, your submodule will be staged. As a consequence, you will need to commit your submodule by using the “git commit” command.


1 Answers

If you want to do this for all submodules, without having to change directories, you can perform

git submodule foreach git reset --hard 

You can also use the recursive flag to apply to all submodules:

git submodule foreach --recursive git reset --hard 
like image 182
theraven Avatar answered Oct 11 '22 11:10

theraven