gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 13:59:53 25 4
gpt4 key购买 nike

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' 选项看起来像是从 hunk 中分出单独行的正确选项。但是,当我输入它时,git 只是再次输出帮助文本。

谁能告诉我应该在文档中的哪个位置查看?

最佳答案

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

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

修改文件后,键入:

git add -p

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

这会让您进入编辑模式以更改大块头。

如果您在这个特定的 hunk 中找到要保留的特定行,请确保将其 +- 保留在那里,并按照描述编辑其他行在快速指南中。

示例时间

假设我有以下更改:

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

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

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

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

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

我们开始了,只有一行上演,准备提交。

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

关于用于 stage/unstage hunks/lines 的 git CLI 命令,如 sourcetree,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30778200/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com