Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Better git add -p?

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?

like image 280
Alexander Gladysh Avatar asked May 01 '11 21:05

Alexander Gladysh


People also ask

Should we use git add?

The git add command adds new or changed files in your working directory to the Git staging area. git add is an important command - without it, no git commit would ever do anything. Sometimes, git add can have a reputation for being an unnecessary step in development.

Is git add the same as git add *?

Detail: git add -A is equivalent to git add .; git add -u . The important point about git add . is that it looks at the working tree and adds all those paths to the staged changes if they are either changed or are new and not ignored, it does not stage any 'rm' actions.

What is git add for?

The git add command adds a change in the working directory to the staging area. It tells Git that you want to include updates to a particular file in the next commit. However, git add doesn't really affect the repository in any significant way—changes are not actually recorded until you run git commit .


1 Answers

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.

like image 81
sehe Avatar answered Oct 30 '22 09:10

sehe