git stage/unstage hunks/lines 的 CLI 命令,例如 sourcetree
git CLI commands for stage/unstage hunks/lines like sourcetree
Sourcetree 可以轻松地对大块头进行暂存和取消暂存。并且也很容易 select 大块头中的特定行并暂存或取消暂存它们。我试图弄清楚如何从命令行执行相同的操作。
我尝试在显示命令历史记录面板的情况下在 sourcetree 中执行每个操作。当我执行这些操作时,它没有显示任何命令。对于其他操作,它工作正常。
在命令行上,我在交互模式下使用 git add
,选择补丁选项,然后 select 一个包含多行更改的文件。提示符为:"Stage this hunk [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
这会让您进入编辑模式来更改帅哥。
如果您在这个特定的 hunk 中找到要保留的特定行,请确保将其 +
和 -
保留在那里,并按照快速指南中的描述编辑其他行.
示例时间
假设我有以下变化:
- allScriptsTimeout: 60000,
- getPageTimeout: 60000
+ allScriptsTimeout: 180000,
+ getPageTimeout: 180000
但是我只想上演第一个更改的行。如上所述,键入 git add -p
和 select e
在编辑器中,将 -
更改为 space 并删除您不想暂存的行。
假设我只想暂存 + allScriptsTimeout: 180000,
,我将文件更改为:
- allScriptsTimeout: 60000,
getPageTimeout: 60000
+ allScriptsTimeout: 180000,
我们开始了,只准备了一行,准备提交。
尽管很麻烦,但绝对可以在 git CLI 中添加单独的行 :)
Sourcetree 可以轻松地对大块头进行暂存和取消暂存。并且也很容易 select 大块头中的特定行并暂存或取消暂存它们。我试图弄清楚如何从命令行执行相同的操作。
我尝试在显示命令历史记录面板的情况下在 sourcetree 中执行每个操作。当我执行这些操作时,它没有显示任何命令。对于其他操作,它工作正常。
在命令行上,我在交互模式下使用 git add
,选择补丁选项,然后 select 一个包含多行更改的文件。提示符为:"Stage this hunk [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
这会让您进入编辑模式来更改帅哥。
如果您在这个特定的 hunk 中找到要保留的特定行,请确保将其 +
和 -
保留在那里,并按照快速指南中的描述编辑其他行.
示例时间
假设我有以下变化:
- allScriptsTimeout: 60000,
- getPageTimeout: 60000
+ allScriptsTimeout: 180000,
+ getPageTimeout: 180000
但是我只想上演第一个更改的行。如上所述,键入 git add -p
和 select e
在编辑器中,将 -
更改为 space 并删除您不想暂存的行。
假设我只想暂存 + allScriptsTimeout: 180000,
,我将文件更改为:
- allScriptsTimeout: 60000,
getPageTimeout: 60000
+ allScriptsTimeout: 180000,
我们开始了,只准备了一行,准备提交。
尽管很麻烦,但绝对可以在 git CLI 中添加单独的行 :)