在Git中将特定文件从一个提交移动到另一个提交?(Move Specific files from one commit to another in Git?)
假设我们有2个这样的提交:
commit id: abz contain files : a, b and z commit id: xy contain files : x and y问题是,是否可以将文件z从abz移动到xy,如果是,那么如何?
Let's say we have 2 commits like these :
commit id: abz contain files : a, b and z commit id: xy contain files : x and yThe question is, is it possible to move file z from abz to xy, if it is, then how?
最满意答案
您可以使用abz文件cherry-pick提交,然后取消其中的所有更改,然后添加相关内容并提交新更改
以下是一系列可帮助您执行此操作的命令:
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!You could cherry-pick the commit with abz files and then unstage all the changes in it and after that add the relevant things and commit a new change
Following is the series of commands that will help you do so:
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!更多推荐
发布评论