开发者

How to exclude files from merge in Git?

开发者 https://www.devze.com 2023-04-05 18:16 出处:网络
Suppose I merge a branch to the master. Since I do not want to merge everythingI run git merge --no-commit, check merged files manuall开发者_开发技巧y, and decide to exclude some of them from the merg

Suppose I merge a branch to the master. Since I do not want to merge everything I run git merge --no-commit, check merged files manuall开发者_开发技巧y, and decide to exclude some of them from the merge. So, I run git reset HEAD <file> and git checkout <file> for every file I want to exclude from the merge.

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


That should work. You can also checkout 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


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


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

git checkout HEAD -- top/middle/mydirectory  

would restore all the files within 'mydirectory'

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号