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

问题描述 投票:4回答:1

假设我们有2个这样的提交:

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

commit id: xy
contain files : x and y

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

git
1个回答
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!
© www.soinside.com 2019 - 2024. All rights reserved.