简体   繁体   English

如何使用magit从提交中编辑差异

[英]how to use magit to edit diff from a commit

I have committed some changes and in the diff shows some things that they are not necessary. 我已经进行了一些更改,并且在差异中显示了一些不必要的东西。

for example: position:relative; 例如:position:relative;
- background: whitesmoke; -背景:白烟; } }
+ background: #f5f5f5; +背景:#f5f5f5; } }

So I want to erase this entries. 所以我想删除这些条目。 Can I use magit to do this. 我可以使用magit来做到这一点。 If not how can be this possible to be done? 如果没有,怎么办呢?

You can use v on the hunk you want to revert, then you can either: 您可以在要还原的块上使用v ,然后可以:

  • amend the commit ( c a ) to change the last commit 修改提交( c a )以更改最后一次提交
  • just commit, and use E (interactive-rebase) to squash your revert change with the old commit 只需提交,然后使用E (interactive-rebase)压缩旧提交的还原更改

If at the beginning the hunk is too big and contain several change, some of them you want to discard, and other you want to retain, then you can select the line that you want to discard before using v 如果一开始的块太大,并且包含多个更改,其中一些要丢弃,而另一些要保留,则可以在使用v之前选择要丢弃的行

Note the hunk is only a part of the commit, magit will highlight the hunk you currently are on. 注意,块只是提交的一部分,magit会突出显示您当前所在的块。 You can also revert completely the commit by using v in the header of the commit. 您还可以通过在提交标头中使用v完全还原提交。

With recent git and magit version, you can also make fixup commit, then use git rebase interactive --autosquash to automatically squash the fixup commit. 使用最新的git和magit版本,您还可以提交fixup提交,然后使用git rebase interactive --autosquash自动git rebase interactive --autosquash fixup提交。

This is what I would do, in the magit diff hit enter on the line you want to change it will take you to specific line in the file where you have made the changes. 这是我会做什么,在magit DIFF打你想改变它会带你到指定的行,你所做的更改的文件中的行进入 Make your changes then amend the commit by pressing c followed by a in the magit-status-buffer . 然后做的更改修改按c然后在提交magit-status-buffer

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

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