开发者

Can I make "git gui" pass, say, "--patience" to "git diff"?

开发者 https://www.devze.com 2023-04-11 13:44 出处:网络
I\'m really just looking for a way to configure git gui to generate diffs as 开发者_开发知识库if by git diff --patience, but I strongly suspect that any mechanism which might allow me to do this would

I'm really just looking for a way to configure git gui to generate diffs as 开发者_开发知识库if by git diff --patience, but I strongly suspect that any mechanism which might allow me to do this would allow other options to be passed as well, and so I ask the more general question in the interest of serving posterity better:

Is there a way to set some git diff options that git gui should use in generating the diffs it shows?


As far as I can tell, there doesn't seem to be a general way to do this. There is a particular config option for setting the number of context lines to show (gui.diffcontext) but no generic config option to add other arguments to the invocation of git diff-index.

However, git-gui is written in Tcl, so it's easy to add this option. If you find diff.tcl on your system* you can just add the line lappend cmd --patience after the line lappend cmd -p.

* It might be /usr/share/git-gui/lib/diff.tcl if you're using a packaged version...


Thanks to Pat Thoyts, the maintainer of git gui, for pointing out in the comments below that a gui.diffopts option has been now been added to git gui so that you can customize the options used for diffs. (That change was introduced in this commit but as far as I know is not in a released version of git yet.)


@Mark Longair's answer hinted at it, but here is the full command you can use, with the --global flag set because I'm assuming you want this forever throughout, instead of for just the single git-gui instance.

git config --global gui.diffopts --diff-algorithm=patience

You could also use any of the following three commands as well if you'd like to try other diff algorithms. https://luppeng.wordpress.com/2020/10/10/when-to-use-each-of-the-git-diff-algorithms/ gives a good visual demonstration of the different results.

  • git config --global gui.diffopts --diff-algorithm=histogram
  • git config --global gui.diffopts --diff-algorithm=meyer
  • git config --global gui.diffopts --diff-algorithm=minimal
0

精彩评论

暂无评论...
验证码 换一张
取 消