我如何只使用SmartGit / Hg提交特定的行 [英] How do I only commit specific lines using SmartGit/Hg

查看:524
本文介绍了我如何只使用SmartGit / Hg提交特定的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SmartGit / Hg。我编辑了一些处理两个独立新功能的文件。现在,当我完成 Feature A 的工作时,我想提交我的工作,但我不能提交所有已编辑的文件,因为它们包含 Feature B 的更改,我不想立即提交。

解决方案

您可以使用 stage 命令。首先, stage 包含要提交更改的所有文件。在这个例子中,除了> DoNotCommit.php 之外的所有文件至少包含一行我们要提交的行:索引编辑器 包含特征A 特征B 行的文件。在这个例子中,我们需要检查 Main.php NewFeatures.php :索引编辑器 您会看到三个标签: Repository(HEAD) Index 工作树

对于我们来说,只有 Repository(HEAD)索引标签很重要。 资源库(HEAD)选项卡显示文件的已提交内容。 索引标签显示我们要提交的更改。假设我们只想提交第一个代码块,使用 myNewCompletedFeature 函数:索引提交的代码>选项卡。这不会工作树中移除代码,这意味着您不会丢失任何更改。现在我们对新的 NewFeatures.php 文件进行同样的操作,并再次保存: 确保在提交窗口中选择分阶段更改



哇,我们现在就完成了!


I'm using SmartGit/Hg. I edited some files working on two separate new features. Now as I finished working on Feature A, I want to commit my work, but I can't just commit all my edited files, as they contain changes of Feature B, which I do not want to commit just now.

解决方案

You can achieve that using the stage command. First of all, stage all the files containing changes to be committed. In this example, all the files except the one called DoNotCommit.php contain at least one line we want to commit:

Next, we need to open the Index Editor for all files containing lines of Feature A and Feature B. In this example, we need to check Main.php and NewFeatures.php:

This opens the Index Editor. You see three tabs with your code: Repository (HEAD), Index, Working Tree:

For us, only the Repository (HEAD) and the Index tab are important. The Repository (HEAD) tab shows the already committed content of the file. The Index tab shows the changes we are going to commit. Let's say we only want to commit the first block of code, with the myNewCompletedFeature function:

As you see, we remove all the code we do not want to commit from the Index tab. This does not remove the code from the Working Tree, meaning you do not loose any of your changes. Now we do the same with our new NewFeatures.php file and save again:

In the last step, we are going to actually commit the new feature. Make sure to select Staged Changes in the commit window!

Wow, we are done now!

这篇关于我如何只使用SmartGit / Hg提交特定的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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