Better git add -p?

后端 未结 3 1380
失恋的感觉
失恋的感觉 2021-01-04 18:22

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

相关标签:
3条回答
  • 2021-01-04 18:53

    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.

    0 讨论(0)
  • 2021-01-04 19:00

    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?

    0 讨论(0)
  • 2021-01-04 19:02

    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.

    0 讨论(0)
提交回复
热议问题