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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 05:41:32  来源:igfitidea点击:

Git: show more context when using git add -i or git add -e?

git

提问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 diffhas 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-indexcan help:

像这样的外部工具jjlee/git-meld-index可以帮助:

git-meld-indexruns meld-- 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 -por the staging feature in tools like git 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对要跳过的每个更改说“ ”