git CLI命令用于stage / unstage hunks / lines,如sourcetree

时间:2015-06-11 10:24:39

标签: git command-line-interface atlassian-sourcetree

Sourcetree可让您轻松上演和取消爵士乐。并且还可以轻松地从大块和舞台中选择特定线条或者取消它们。我试图找出如何从命令行执行相同操作。

我尝试在sourcetree中使用命令历史记录面板显示每个操作。执行这些操作时,它不显示任何命令。对于其他操作,它可以正常工作。

在命令行中,我在交互模式下使用git add,选择补丁选项,然后选择其中包含多行更改的文件。提示符是:“这个大块[y,n,q,a,d,/,e,?]?”。如果我选择'?'选项它输出此帮助文本:

y - stage this hunk
n - do not stage this hunk
q - quit; do not stage this hunk or any of the remaining ones
a - stage this hunk and all later hunks in the file
d - do not stage this hunk or any of the later hunks in the file
g - select a hunk to go to
/ - search for a hunk matching the given regex
j - leave this hunk undecided, see next undecided hunk
J - leave this hunk undecided, see next hunk
k - leave this hunk undecided, see previous undecided hunk
K - leave this hunk undecided, see previous hunk
s - split the current hunk into smaller hunks
e - manually edit the current hunk
? - print help

's'选项看起来是正确的选项,用于将各个线路从大块中分段出来。但是,当我输入它时,git只会再次输出帮助文本。

任何人都可以告诉我在文档中的位置吗?

1 个答案:

答案 0 :(得分:4)

派对迟到了,但它可能会帮助其他人寻找解决方案。

git倾向于在同一个大块附近添加行 - 如果你想逐行分段代码,你可以在交互模式下编辑这些代码。

修改文件后,键入:

git add -p

现在,您可以输入s而不是e

这将带您进入编辑模式以更改大块。

如果您要在此特定大块中找到要保留的特定行,请务必将其+-保留在其中,然后按照快速指南中的说明编辑其他行。< / p>

示例时间

我们说我有以下变化:

-  allScriptsTimeout: 60000,
-  getPageTimeout: 60000
+  allScriptsTimeout: 180000,
+  getPageTimeout: 180000

但是我只想暂停第一个更改的行。如上所述,键入git add -p并选择e

在编辑器中,将-更改为空格并删除不想播放的行。

我们说我只想要+ allScriptsTimeout: 180000,上演,我将文件更改为:

-  allScriptsTimeout: 60000,
   getPageTimeout: 60000
+  allScriptsTimeout: 180000,

我们走了,只有一条线上演,准备好承诺。

虽然很麻烦,但绝对可以在git CLI中添加单独的行:)