我怎样才能将SourceTree的过去未推送的提交分割? [英] How can I split a past un-pushed commit with Sourcetree?
问题描述
有没有办法用Sourcetree做到这一点?或者是这样的地方之一,我必须下拉到命令行来完成我的目标?解析方案
从 git help rebase code>
(搜索SPLITTING COMMITS)。这不是一个git命令或选项;它更多的是提交编辑的方式。您可以使用SourceTree for Mac执行上述步骤。从你的问题中,我明白你之前使用SourceTree进行过交互式重新组合,并且熟悉它的用户界面。
看来我的原始答案(见上文)太神秘了。没有用于分割提交的特殊 git
命令,因此 SourceTree
不会在界面中提供命令或选项要做到这一点。您必须使用GUI阅读并遵循文档中介绍的步骤,而不是命令行。
Atlassian SourceTree
: li>使用git rebase -i< commit> ^
开始交互式转化,其中< commit>
是提交你想分裂。实际上,任何提交范围都会执行,只要它包含该提交即可。
点击您想要编辑的提交的父提交。从出现的上下文菜单(< hash>)中选择从
interactively ...
$ b
是被点击的提交的哈希的缩写) li>使用edit动作标记要分割的提交。
SourceTree
打开Interactive Rebase对话框。在列表中确定要分割的提交(这是最后一个提交),并在更改提交栏中检查其复选框。按下确定按钮继续。
- 当编辑提交时,执行
git reset HEAD ^
。结果是HEAD
被回绕一个,并且该索引跟随。但是,工作树保持不变。
SourceTree
在后台运行所需的 Git
命令,并在编辑您标记为修改的提交时停止。右键单击当前 HEAD
的父级,然后选择Reset(no branch,rebasing < branch>
)从出现的上下文菜单(< branch>
是您在启动进程时签出的分支的名称)从此提交。它会问什么模式用于重置;在使用模式列表中选择混合 - 保留工作副本但重置索引,然后按下确定。
- 现在将更改添加到您希望在第一次提交中使用的索引中。您可以使用
git add
(可能交互式地)或git gui
(或两者)来执行此操作。
这是分割时间!将索引添加到您想要的文件和区块投入第一次提交;如果需要,甚至可以执行原始提交中不存在的更改。但是,请注意,在您正在编辑的提交中没有进行的更改可能与稍后提交引入的更改发生冲突。
- 立即提交现在的索引,无论现在提交什么提交消息。
像往常一样使用 SourceTree
并提交分阶段更改。 $ b
- 重复最后两步,直到您的工作树变干净为止。
$ b $ 继续 继续与 git rebase - continueue
。
从操作菜单中选择继续重做。
恭喜!您只需使用由 SourceTree
提供的隐藏split commit命令来分割提交:p
备注
如果出现问题或者您下定决心或出于任何原因需要取消整个过程,请使用中止重做 操作菜单。在后台 SourceTree
会调用 git rebase --abort
,一切都恢复到启动前的状态。
如果您需要在同一分支上拆分/编辑多个提交,可以使用步骤1中最旧的提交,并标记修改步骤中需要的所有提交2.其他所有内容都是相同的, SourceTree
将对您标记为修改的每个提交重复步骤3-7。
这是你如何使用 Atlassian SourceTree
分割一次提交。
任何其他的 Git
带GUI的客户端可以用来代替交互式重新分配。
The interactive rebase capabilities of Sourcetree are great, but I often find myself wanting to be able to "split" a commit into multiple smaller commits. I know theres a way to do this from the command line, but I can't seem to find any place in the UI to handle this.
Is there a way to do this with Sourcetree? Or is this one of those places where I have to drop down to the command line to accomplish my goals?
Splitting the commits from the command line using interactive rebase is explained in git help rebase
(search for "SPLITTING COMMITS"). It is not a git command or option; it is more a way of commits editing. You can do the steps described there using SourceTree for Mac. From your question I understand you did interactive rebases using SourceTree before and are familiar with its UI.
Update:
It seems that my original answer (see above) is too cryptic. There is no special git
command for splitting commits, and consequently SourceTree
does not provide a command or an option in the interface to do that. You have to read and follow the steps explained in the documentation using the GUI instead of the command line.
These are the steps (quoted from the documentation) and how to follow them using Atlassian SourceTree
:
- Start an interactive rebase with
git rebase -i <commit>^
, where<commit>
is the commit you want to split. In fact, any commit range will do, as long as it contains that commit.
Right-click on the parent commit of the commit you want to edit. Select "Rebase children of <hash>
interactively ..." from the contextual menu that appears (<hash>
is the abbreviation of the clicked commit's hash).
- Mark the commit you want to split with the action "edit".
SourceTree
opens the "Interactive Rebase" dialog box. Identify in the list the commit you want to split (it's the last one) and check its checkbox in the column "Amend Commit?". Press the "OK" button to continue.
- When it comes to editing that commit, execute
git reset HEAD^
. The effect is that theHEAD
is rewound by one, and the index follows suit. However, the working tree stays the same.
SourceTree
runs in the background the needed Git
command(s) and stops when it comes to edit the commit you marked for amending. Right click the parent of the current HEAD
and select "Reset (no branch, rebasing <branch>
) to this commit" from the contextual menu that appears (<branch>
is the name of the branch you had checked out when you started the process). It will ask what mode to use for reset; select "Mixed - keep working copy but reset index" in the "Using mode" list and press "OK".
- Now add the changes to the index that you want to have in the first commit. You can use
git add
(possibly interactively) orgit gui
(or both) to do that.
It's split time! Add to the index the files and the hunks you want to put into the first commit; you can even do changes that were not present in the original commit if you need. However, be aware that changes that were not in the commit you are editing may conflict with changes introduced by the later commits.
- Commit the now-current index with whatever commit message is appropriate now.
Use SourceTree
as usual and commit the staged changes.
- Repeat the last two steps until your working tree is clean.
(no comments)
- Continue the rebase with
git rebase --continue
.
Pick the "Continue Rebase" from the "Actions" menu.
Congratulations! You just split a commit using the hidden "split commit" command provided by SourceTree
:p
Remarks
If something goes wrong or you make up your mind or for whatever reason you need to cancel the entire process then use the "Abort Rebase" from the "Actions" menu. In the background SourceTree
will invoke git rebase --abort
and everything well return to the state it was before you started.
If you need to split/edit more than one commit on the same branch you can use the oldest commit on step 1 and mark for amending all the commits you need on step 2. Everything else is the same, SourceTree
will repeat the steps 3-7 for each commit you marked for amending.
This is how you can split a commit using Atlassian SourceTree
.
Any other Git
client with GUI that provides a way to do interactive rebase can be used instead.
这篇关于我怎样才能将SourceTree的过去未推送的提交分割?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!