Git:使用 git add -i 或 git add -e 时显示更多上下文?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6711670/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git: show more context when using git add -i or git add -e?
提问by Shawn J. Goff
I'm selectively committing parts of a large file and I'd like to see more context around each hunk. Is this possible?
我有选择地提交了一个大文件的一部分,我希望看到每个大文件的更多上下文。这可能吗?
回答by hammar
Short answer: no.
简短的回答:没有。
git diff
has the -U<n>
option which allows you to customize the number of lines to show around a change. For example, git diff -U5 ...
will show 5 lines of context. As far as I can tell, there is no such option available for the diff display in the interactive mode.
git diff
具有-U<n>
允许您自定义要在更改周围显示的行数的选项。例如,git diff -U5 ...
将显示 5 行上下文。据我所知,交互模式下的差异显示没有这样的选项。
回答by VonC
To confirm, this is still not possible in 2019.
确认一下,这在 2019 年仍然是不可能的。
An external tool like jjlee/git-meld-index
can help:
像这样的外部工具jjlee/git-meld-index
可以帮助:
git-meld-index
runsmeld
-- or any other git difftool (kdiff3
,diffuse
, etc.) -- to allow you to interactively stage changes to the git index (also known as the git staging area).
git-meld-index
运行meld
-- 或任何其他 git difftool (kdiff3
,diffuse
, 等) -- 以允许您以交互方式暂存对 git 索引(也称为 git 暂存区)的更改。
This is similar to the functionality of git add -p
, and git add --interactive
.
这类似于git add -p
, 和的功能git add --interactive
。
In some cases meld is easier / quicker to use than
git add -p
or the staging feature in tools likegit gui
.
That's because meld allows you, for example, to:
- see more context,
- see intra-line diffs
- edit by hand and see 'live' diff updates (updated after every keypress)
- navigate to a change without saying '
n
' to every change you want to skip
在某些情况下,MELD更容易/更快地使用比
git add -p
或类似工具的升级功能git gui
。
这是因为,例如,meld 允许您:
- 查看更多上下文,
- 查看行内差异
- 手动编辑并查看“实时”差异更新(每次按键后更新)
- 导航到更改而不
n
对要跳过的每个更改说“ ”