在提交之间移动文件 [英] Move files between commits

查看:58
本文介绍了在提交之间移动文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在本地历史记录中的某个地方,我有两次相应的提交,并且一个文件被错误地添加到了第二个文件中.我想解决这种情况.

I have two consequential commits, somewhere in the local history, and one file was mistakenly added into the second. I want to fix the situation.

我不知道如何使用交互式资源库.我做了 git rebase -i HEAD〜10 ,然后选择编辑带有文件的提交,以便从那里签出.我使用git guit,但是在提交区域中看不到任何文件.我可以选择修改先前的提交,然后再查看文件.但是,我无法将放错位置的文件添加到该先前的提交中,因为我看不到当前提交中的文件.

I do not understand how should I use the interactive rebase. I did git rebase -i HEAD~10 and choosen to edit the commit with file in order to check it out from there. I use git guit but, see no files in the commit area. I can choose to amend the previous commit then I see the files. But, I cannot add the misplaced file to that previous commit since I do not see the file in the current commit to start with.

推荐答案

如果我没弄错的话,您想要的是将其中包含的一些更改移至commit 1到commit1.

If I don't get it wrong, what you want is move some change that was included commit 2 to commit 1.

我发现最简单的方法是进行两个连续的交互式变基.

I find the easiest way to do that is doing two consecutive interactive rebases.

在第一个中,您将提交2分成两个提交:第一个仅包含要移动的更改,第二个包含所有其余内容.现在,我们提交了1、2.1和2.2.

In the first one, you split commit 2 into two commits: the first including just the change you want to move, and the second including all the rest. We have now commits 1, 2.1, and 2.2.

然后重新设置基准,这次选择将2.1压缩为1.

Then you rebase again, and this time choose to squash commit 2.1 into 1.

这篇关于在提交之间移动文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆