Elad Benda
Elad Benda

Reputation: 36654

what is the difference between ~/.gitignore and `git update-index --assume-unchanged`

I changed some settings in my config file which I don't want to push to the remote repository.

I want it to effect only one project locally.

I saw there are few ways to do so:

Per Computer: through settings in ~/.gitconfig

I'm using SourceTree and only when I use option (2) I see the files are vanished from the UI.

What is the difference between (1) and (2) ?

Does it really means that the files are not ignored when I see them in the SourceTree after using option (1) ?

Upvotes: 1

Views: 385

Answers (1)

Schleis
Schleis

Reputation: 43700

The .gitignore file prevents files from showing up as files to be added to the repository. If the file is already in the repo when it is added to the .gitignore file, any changes to the file will be shown by git and can be committed. The .gitignore settings only affect new files that are in the repos path. You would use this for keeping temp files created by you IDE or compile files from showing up and cluttering your list of files that you modified when you do git status.

git update-index --assume-unchanged doesn't show that a file was changed at all. If you make any modifications to the file, git won't show that it has been modified in git status. You would use this with config files for users. When the repository gets cloned they need to have the file but there may be some changes that they need so that they can use the code (i.e. change a file path for their local machine). But you don't want them to accidentally commit the file and mess up things for others when they pull in the changes.

For changes to a config file, you want to use the git update-index option. You want the config file in the repo but you don't want to commit the changes to it.

Upvotes: 1

Related Questions