在Git中将特定文件从一个提交移动到另一个提交?

时间:2017-12-24 17:23:35

标签: git

我们说我们有2个这样的提交:

commit id: abz
contain files : a, b and z

commit id: xy
contain files : x and y

问题是,是否可以将文件z从abz移动到xy,如果是,那么如何?

1 个答案:

答案 0 :(得分:3)

您可以cherry-pick使用abz文件进行提交,然后取消其中的所有更改,之后添加相关内容并提交新更改

以下是一系列有助于您这样做的命令:

git cherry-pick -n <commit> # get your patch, but don't commit (-n = --no-commit)
git reset                   # unstage the changes from the cherry-picked commit
git add -p                  # add the changes you do want
git commit                  # make the commit!