简体   繁体   English

修改作为magit中rebase的一部分编辑的提交

[英]Amending commit that is edited as part of a rebase in magit

I'm using Emacs + it's in very many ways fabulous magit-mode to work with git. 我正在使用Emacs +它在很多方面很棒的magit模式与git一起工作。 There is one aspect of my workflow though that I can't map to this, and thus this question. 我的工作流程有一个方面,我无法映射到这个,因此这个问题。

Sometimes you have a commit which should be reworked into separate commits. 有时候你有一个提交应该重新设计成单独的提交。 I can interactively rebase my commits with magit, and declare my intend to edit said commit. 我可以使用magit以交互方式重新提交我的提交,并声明我打算编辑所述提交。

Now I have to switch over to git gui, select "ammend last commit" which shows me the staged changes, and unstage those parts I want to become a separate commit. 现在我必须切换到git gui,选择“ammend last commit”,它显示了我的分阶段更改,并取消了我想成为单独提交的那些部分。 Then I commit, stage the exclusions, and commit again - voila, I have a new commit within my history. 然后我提交,分阶段排除,再次提交 - 瞧,我的历史中有一个新的提交。

I have so far not found a way to accomplish this using Emacs. 到目前为止,我还没有找到使用Emacs实现此目的的方法。 Any hints? 任何提示?

After your begin the rebase, instead of going to the gui, do a magit-reset-head to HEAD~1, this will put you in the position to unstage the changes, and stage and commit as desired before finally Continuing the rebase from the magit status buffer. 在你开始使用rebase之后,而不是去gui,做一个magit-reset-head到HEAD~1,这将使你处于取消更改的位置,并根据需要进行阶段和提交,最后继续从magit状态缓冲区。


Example scenario workflow: 示例场景工作流程

  1. commit changes to file A (commit 1) 提交对文件A(提交1)的更改
  2. commit changes to file B and file C (commit 2) 提交对文件B和文件C的更改(提交2)
  3. commit changes to file D (commit 3) 提交对文件D的更改(提交3)
  4. realize that you want the changes to file B and file C to be separate commits 意识到你希望对文件B和文件C的更改是单独的提交
  5. run magit-log 运行magit-log
  6. begin an interactive rebase ( E ) at commit 2. 在提交2处开始交互式rebase( E )。
  7. specify you want to edit ( e ) commit 2 and finish ( Cc Cc ) 指定您要编辑( e )提交2并完成( Cc Cc
  8. return to magit status buffer. 返回magit状态缓冲区。
  9. run magit-reset-head ( x ), specify HEAD~1 in prompt. 运行magit-reset-headx ),在提示符下指定HEAD~1
  10. you will see the changes for commit 2 staged. 你会看到提交2阶段的变化。
  11. unstage the changes to file C. 取消对文件C的更改。
  12. commit the staged changes for file B. 提交文件B的分阶段更改。
  13. stage and commit the changes to file C. 暂存并将更改提交到文件C.
  14. continue and finish the rebase with R C R C继续并完成变基

You will now have four commits, each changing one file in the order A, B, C, D. 您现在将有四个提交,每个提交按A,B,C,D顺序更改一个文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM