10

Sometimes I work on system without X Window installed, and can't use Git GUI.

What are existing console alternatives to the git add -p?

I like almost everything that it does (more than Git GUI actually), but I hate that it does not let me view the whole picture and choose the order that I want to review the chunks. That's the only actual advantage of Git GUI over git add -p to me, but it is rather crucial one.

I tried tig, but I do not like the user experience that it offers.

Any suggestions?

2
  • Are you aware of the 'g' command? It's certainly less than ideal, but it does give you a list of all hunks and the ability to move to a particular hunk (effectively letting you choose the order). May 2, 2011 at 14:37
  • I am aware of it, but it is not good enough — I need to see all hunks in a file as whole to decide if I want to commit them now. May 4, 2011 at 2:29

3 Answers 3

19

Vim has a plugin 'fugitive'

Edit: the linked vimcast (comments) is excellent and I recommend it. I would like to add the hint that there will normally not be a need to type :diffget and :diffput in longhand, because you can do he same directly in normal/visual mode by pression do and dp.

The best command to start with for this feature appears to be :Gstatus


Vim is a terminal editor (which so happens to have a gui port too)

The fugitive plugin will simply let you edit the index and worktree versions of files alongside each other and let you diffput/diffobtain until you're satisfied. Vim's diff mode is sophisticated, and much more flexible/intuitive than git add --patch.

  • scrollbinding
  • syntax highlighting and intra-line (wordlevel) diff highlighting simultaneously
  • automatic diff folding (of unchanged regions)

You can get fugitive here

Snippet from :he fugitive:

Edit a file in the work tree and make some changes. Use |:Gdiff| to open up the indexed version. Use |do| and |dp| on various hunks to bring the files in sync, or use |:Gread| to pull in all changes. Write the indexed version to stage the file.

2
0

what about a simple

git diff

to "view the whole picture" and then a

git add -i
5

to chose the first file you want to commit, stage the hunks, and then repeat the process with the next files?

7
  • 1
    does the '5' have a meaning there?
    – sehe
    May 1, 2011 at 21:56
  • 1
    I'd like to be able to do all of this simultaneously. Often I have several series of uncommitted hunks sitting in several different files (that would be one series per commit). Running through git add -p loop for each one each time is rather tedious. Also this use of git add -i is the same as using actual file name in git add -p invocation, not much improvement. May 1, 2011 at 21:58
  • @sehe: that's a file list menu item number. May 1, 2011 at 21:58
  • @Alexander Gladysh: I'm not sure what you mean - thought of giving you some more overview by git add -i (e.g. seeing lines of codes changed). And yes, you have to call git add -i and git commit for every different/next commit, but that's how git works. What do you mean precisely with to do "all simultaneously"?
    – Markus
    May 1, 2011 at 22:14
  • 1
    @Alexander Gladysh: Then you're out of luck with me. The only other hint I can give you, is to change your coding style to do changes for only one and small commit at a time and commit them before you start working on the next commit. Then you don't need to delegate changes to different commits, and that's more the philosophy of git: do one thing at a time. Make small commits. If you work on different things, create a temp-branch for each. Merge/Rebase them accordingly.
    – Markus
    May 2, 2011 at 9:44
0

If I were in the same situation as you (a mix of hunks where some hunks are 'more important' than others), I'd commit the lesser hunks into their own commits with easily distinguishable commit message and leave only those 'more important' hunks so that they don't get in the way of diffs, or git add -i.

With the easily distinguishable commit messages for the "less privileged" hunks it should be easy to deal with them later.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.