Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Git how can I stage a file I have just diffed without manually specifying the file?

Tags:

git

bash

I frequently diff a file, decide it's what I'll stage and then have to run the git add /long/path/to/file to manually specify the file.

A usual work flow would go along the lines of:

git status

"oooh changes"

git diff /long/path/to/changed/file

"Yup, I remember that - commit time!"

git add /long/path/to/changed/file

Obviously this isn't the hardest thing in the world to do, it just gets a little tedious. I know I could go into interactive mode too, but that's never really fitted my work flow.

So I'm looking for some magic unix or git command where I can say "Hey, that file I just diffed - stage it please!".

Does something like that exist in either Git or Bash? Or is it something I need to build in a bash script?

like image 275
ghickman Avatar asked Feb 10 '11 10:02

ghickman


1 Answers

Use

git add !$

More info: http://www.cyberciti.biz/faq/shell-call-last-argument-of-preceding-command/

like image 158
Dogbert Avatar answered Oct 04 '22 02:10

Dogbert