繁体   English   中英

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

[英]git CLI commands for stage/unstage hunks/lines like 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只会再次输出帮助文本。

任何人都可以告诉我在我应该看的文档中的哪个位置?

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

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

修改文件后,键入:

git add -p

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

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

如果你发现你想保持在这个特殊的大块举办一个特定的行,一定要离开它的+-在那里和快速指南中的说明,修改等。

示例时间

假设我有以下变化:

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

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

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

假设我只想要+ allScriptsTimeout: 180000,要暂存,我将文件更改为:

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

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

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

暂无
暂无

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

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