How to exclude files from merging in Git?

Suppose I connect a branch to a master. Since I don't want to merge everything that I run git merge --no-commit , check the merged files manually and decide to exclude some of them from the merge. So, I run git reset HEAD <file> and git checkout <file> for each file that I want to exclude from the merge.

Does it make sense? Is there a better way to do this?

+4
source share
3 answers

That should work. You can also check each file from the version where you were:

 git checkout HEAD -- <a list of the files you want to not change> 

Why, may I ask, do you need to do this?

Hope this helps

+3
source

There is no need to do git reset HEAD <file> before git checkout <file> . A single git checkout <file> will do the same.

+1
source

Please note that it can also work for directories, as in this thread :

 git checkout HEAD -- top/middle/mydirectory 

will recover all files within < mydirectory

+1
source

All Articles