Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git commit without staging [duplicate]

Tags:

git

git-commit

I noticed that git allows to commit a tracked file (which was modified locally) directly without using staging, eg:

$ git status -s .
 M   myfile.txt
$ git commit myfile.txt -m"1 way"

Is it better to use, instead, the "classic" two steps ? :

$ git add myfile.txt
$ git commit myfile.txt -m"2 way"

1 Answers

Try git commit -a -m [message]

-a

Tell the command to automatically stage files that have been modified and deleted, but new files you have not told Git about are not affected.

Doesn't work for new files, you still need to explicitly add them.

It's just stage followed by commit in a single step. I find this convenient since one can see all changed states when using status and we typically make small incremental commits.

like image 64
Ivan Choo Avatar answered Jul 22 '26 02:07

Ivan Choo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!