在Git中将特定文件从一个提交移动到另一个提交?(Move Specific files from one commit to another in Git?)

编程入门 行业动态 更新时间:2024-10-27 18:28:58
在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 y

The 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!

更多推荐

本文发布于:2023-08-06 11:21:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1448469.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中将   文件   Git   Move   commit

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!