git CLI命令,用于舞台/舞台的大块/如sourcetree的行 [英] git CLI commands for stage/unstage hunks/lines like sourcetree
问题描述
Sourcetree使得上演和不上演的帅哥很容易.并且还可以轻松地从大块中选择特定的行,并对其进行舞台化或取消舞台化.我试图找出如何从命令行执行相同的操作.
Sourcetree makes it easy to stage and unstage hunks. And also easy to select particular lines from within a hunk and stage or unstage them. I am trying to figure out how to do the same from the command line.
我尝试在显示命令历史记录面板的情况下在sourcetree中执行每个操作.当我执行这些操作时,它没有显示任何命令.对于其他操作,它工作正常.
I tried doing each operation in sourcetree with the command history panel showing. It doesn't show any commands when I perform these operations. For other operations it works fine.
在命令行上,我在交互模式下使用git add
,选择补丁程序选项,然后选择其中有多行更改的文件.提示是:在此大块[y,n,q,a,d,/,e ,?]登台?".如果我选择?"选项,它输出以下帮助文本:
On the command line, I use git add
in interactive mode, choose the patch option and then select a file with a multiline change in it. The prompt is: "Stage this hunk [y,n,q,a,d,/,e,?]?". If I choose the '?' option it outputs this help text:
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只会再次输出帮助文本.
The 's' option looks like the right one for staging individual lines out of the hunk. However, when I enter it, git just outputs the help text again.
有人可以告诉我我应该在文档中找什么地方吗?
Can anyone tell me where in the docs I should be looking?
推荐答案
晚些时候参加聚会,但这可能会帮助其他人寻找解决方案.
late to the party, but it might help others looking for a solution.
git倾向于在靠近同一块的位置添加行-如果要逐行暂存代码,则可以在交互模式下编辑块.
git tends to add lines in close proximity to the same hunk - if you want to stage code line by line, you can edit the hunks in interactive mode.
修改文件后,键入:
git add -p
现在,您可以输入e
代替s
.
And now, instead of s
you can type e
.
这将带您进入编辑模式以更改结块.
Which brings you into an edit mode to change the hunk.
如果找到要保留在该特定块中的特定行,请确保将其+
和-
留在此处,并按照快速指南中的说明编辑其他行.
If you find a particular line you want to keep for staging in this particular hunk, make sure to leave its +
and -
in there and edit the others as described in the quick guide.
假设我有以下更改:
- allScriptsTimeout: 60000,
- getPageTimeout: 60000
+ allScriptsTimeout: 180000,
+ getPageTimeout: 180000
但是,我只想上演第一条更改的行.如上所述,输入git add -p
并选择e
However I only want to stage the first changed line. As explained above type git add -p
and select e
在编辑器中,将-
更改为一个空格,并删除您不想暂存的行.
Within the editor, change the -
to a space and remove the lines you do not want staged.
假设我只想暂存+ allScriptsTimeout: 180000,
,我将文件更改为此:
Let's say I want only + allScriptsTimeout: 180000,
to be staged, I change the file to this:
- allScriptsTimeout: 60000,
getPageTimeout: 60000
+ allScriptsTimeout: 180000,
然后我们走了,只有一行准备好要提交.
And there we go, just one line staged, ready to be committed.
尽管麻烦,但绝对可以在git CLI中添加单独的行:)
Albeit cumbersome, it is definitely possible to add individual lines within git CLI :)
这篇关于git CLI命令,用于舞台/舞台的大块/如sourcetree的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!