How do I only commit specific lines using SmartGit/Hg

回眸只為那壹抹淺笑 提交于 2019-12-03 12:36:44

问题


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.


回答1:


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!



来源:https://stackoverflow.com/questions/24386596/how-do-i-only-commit-specific-lines-using-smartgit-hg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!