1

I do this all the time:

git add . git add -A git commit -am "foobar" 

that adds everything so all of my changes are staged, but we have a git submodule in the config directory.

What I have been doing is using several of these commands to "get rid of changes to the config dir":

git reset -- config git checkout -- config git checkout origin/dev config git reset HEAD config 

Can anyone explain what these are doing? I am not even sure if the last command is doing what I think it does.

1 Answer 1

1

First, you don't need to repeat git add . and git add -A. They both add everything if you are on the root folder of your repo.

Second, use git add -p instead: you will be able to ignore changes to the commit submodule folder that way (since Git 2.17). And you will add only what you need for the next commit, making smaller, more granular commits.

But if you add added config, and do not have committed yet, then:

  • git reset config would unstage (remove from index) the config submodule entry
  • git checkout origin/dev -- config would ensure the SHA1 of that config is the one from what was fetched from origin (branch dev), not any local changes you might have done.

You don't need the other commands. I would add a git submodule update --checkout in order to make sure the content of the submodule is checked out to the right SHA1.

Sign up to request clarification or add additional context in comments.

1 Comment

MrCholo approves of this message.