git cherry-pick合并删除文件

时间:2013-03-28 19:14:02

标签: git cherry-pick

我正试图在git中挑选一个提交,它添加了一堆文件,但也修改了我的分支中尚不存在的文件。

存在一个冲突,即要添加的文件都已暂存,并且在提交中更改但在分支中尚不存在的文件不会暂存,并列为:

deleted by us: app/changed_file.rb

如果我只提交暂存文件,那么当changed_file.rb最终合并到分支中时会导致问题吗?

2 个答案:

答案 0 :(得分:3)

https://www.kernel.org/pub/software/scm/git/docs/git-cherry-pick.html

Cherry-pick会创建提交,因此如果省略分支中不存在但存在于分支中的文件,那么最终将不会发生任何事情。

mkdir test && cd test && git init && touch foo.txt
git add foo.txt && git commit -m "Init repo"
git branch test && git checkout test && vi foo.txt 
git add foo.txt && git commit -m "Changed foo on branch test"
git checkout master && touch bar.txt
git add bar.txt && git commit -m "Create bar.txt"
vi bar.txt 
touch baz.txt && git add . && git commit -m "Will be cherry picked"
git checkout test && git cherry-pick bfd1b58
git rm bar.txt && git commit
git checkout master && git merge test

由于lsbar.txt baz.txt foo.txt

答案 1 :(得分:1)

如果不需要,您只需从正在提交的提交中删除该文件......

git rm file_name

git commit

- 确保您的提交消息包含Change ID:line作为最后一段

git push origin HEAD:refs / for / branch_name

这样你就不会有任何冲突,下次会让你的合并更容易..