Search code examples
gitdiffgit-diffgit-indexgit-stage

Can you stage a file (or at least, a section of a file) DURING a git diff?


Before I stage files, I like to perform a git diff to check that everything is okay. While I'm vertically traversing down a diff, I make a mental note of each file that is "OK" for staging. If it's a particularly long diff, I find it hard to keep track of which ones were OK'ed, so I tend to quit out of the diff at intervals and stage what I can. This gets a bit tedious.

Is there a way I can improve this workflow? Obviously, one should not let their diff get huge in the first place, but sometimes things don't work out like that (e.g. changing the method signature for a method that is called across many files).

For instance, is it possible to stage everything from the "top" of the currently active git diff "session" to the current point in the diff that you are at? This way I could just keep staging without quitting the diff and losing my train of thought.


Solution

  • Try using git add -p instead. It will show you each of the diff hunks and ask you if you want to add them.