Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skip to next modified file in git diff?

Tags:

git

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?

like image 779
Abe Miessler Avatar asked Nov 19 '12 23:11

Abe Miessler


People also ask

What is A and B in git diff?

In most cases, Git picks A and B in such a way that you can think of A/- as "old" content and B/+ as "new" content. Let's look at our example: Change #1 contains two lines prepended with a "+". Since no counterpart in A existed for these lines (no lines with "-"), this means that these lines were added.

What is git diff command?

Comparing changes with git diff Diffing is a function that takes two input data sets and outputs the changes between them. git diff is a multi-use Git command that when executed runs a diff function on Git data sources. These data sources can be commits, branches, files and more.

Can you git diff two files?

The git diff command displays the differences between files in two commits or between a commit and your current repository. You can see what text has been added to, removed from, and changed in a file. By default, the git diff command displays any uncommitted changes to your repository.


4 Answers

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.

like image 195
Greg Hewgill Avatar answered Oct 08 '22 16:10

Greg Hewgill


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.)

like image 37
Smithee Avatar answered Oct 08 '22 15:10

Smithee


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>
like image 7
Nikita R. Avatar answered Oct 08 '22 17:10

Nikita R.


I'd suggest you to use tig. 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.

like image 4
mgarciaisaia Avatar answered Oct 08 '22 17:10

mgarciaisaia