Skip to next modified file in git diff?

Git

Git Problem Overview


I made the mistake of upgrading a Visual Studio project from 2008 to 2010 without checking in my previous changes first. Because of this I have a huge system generated file (10k+ lines) that had every 4th line changed.

I'm usually pretty good about checking in stuff often, so I will typically just use the down key to scroll through my changes. In this case it will take several lifetimes to scroll through the changes to the system generated file.

Is there a way to skip to the next modified file after you have done a git diff so that you don't have to scroll through every change on every file?

Git Solutions


Solution 1 - Git

By default, git diff pipes its output through less. So you can use the less commands to search for the next header. Type /^diff and press Enter to skip to the next file.

Solution 2 - Git

While in git diff, simply hit n to go straight to the next file, and again to the one afterwards, and so on.

You can also use N to go back a file.

(For these commands to work, you'll need to first type /^diff and press Enter, as explained in this answer.)

Solution 3 - Git

For other useful commands type h for help (while being in git diff, which is being in less).

In particular:

                           JUMPING

  g  <  ESC-<       *  Go to first line in file (or line N).
  G  >  ESC->       *  Go to last line in file (or line N).
  p  %              *  Go to beginning of file (or N percent into file).
  t                 *  Go to the (N-th) next tag.
  T                 *  Go to the (N-th) previous tag.
  {  (  [           *  Find close bracket } ) ].
  }  )  ]           *  Find open bracket { ( [.
  ESC-^F <c1> <c2>  *  Find close bracket <c2>.
  ESC-^B <c1> <c2>  *  Find open bracket <c1>

Solution 4 - Git

I'd suggest you to use [tig][1]. It's a curses interface for git, and a very good one.

With tig status you can see the index status, and by pressing Enter on any of the files, you see it's diff. h shows you the help menu, but it's a vi-shortcuts-based interface.

I think in any debian-based distro you can just apt-get install it, or you can make it from the linked site.

[1]: http://jonas.nitro.dk/tig/ "Tig homepage"

Solution 5 - Git

Another option is to call update-index command and tell it to pretend that one giant file didn't change. There's a more complete example here.

Solution 6 - Git

I think you want:

:n                *  Examine the (N-th) next file from the command line.

See this in the help for less.

                      CHANGING FILES
:e [file]            Examine a new file.
^X^V                 Same as :e.
:n                *  Examine the (N-th) next file from the command line.
:p                *  Examine the (N-th) previous file from the command line.
:x                *  Examine the first (or N-th) file from the command line.
:d                   Delete the current file from the command line list.
=  ^G  :f            Print current file name.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAbe MiesslerView Question on Stackoverflow
Solution 1 - GitGreg HewgillView Answer on Stackoverflow
Solution 2 - GitSmitheeView Answer on Stackoverflow
Solution 3 - GitNikita R.View Answer on Stackoverflow
Solution 4 - GitmgarciaisaiaView Answer on Stackoverflow
Solution 5 - GitRomanView Answer on Stackoverflow
Solution 6 - GitArthurView Answer on Stackoverflow