Is there any way I can do
git add -A
git commit -m \"commit message\"
in one command?
I seem to be doing those two commands a lot,
I use the following (both are work in progress, so I'll try to remember to update this):
# Add All and Commit
aac = !echo "Enter commit message:" && read MSG && echo "" && echo "Status before chagnes:" && echo "======================" && git status && echo "" && echo "Adding all..." && echo "=============" && git add . && echo "" && echo "Committing..." && echo "=============" && git commit -m \"$MSG\" && echo "" && echo "New status:" && echo "===========" && git status
# Add All and Commit with bumpted Version number
aacv = !echo "Status before chagnes:" && echo "======================" && git status && echo "" && echo "Adding all..." && echo "=============" && git add . && echo "" && echo "Committing..." && echo "=============" && git commit -m \"Bumped to version $(head -n 1 VERSION)\" && echo "" && echo "New status:" && echo "===========" && git status
With the echo "Enter commit message:" && read MSG
part inspired by Sojan V Jose
I'd love to get an if else
statement in there so I can get aacv to ask me if I want to deploy when it's done and do that for me if I type 'y', but I guess I should put that in my .zshrc
file
In the later version of git you can add and commit like this
git commit -a -m "commit message"
Additionally you an alias:
[alias]
ac = commit -a -m
Then you can use it like this:
git ac "commit message"
To keep it in one line use:
gacm "your comment"
For the silver backs in the crowd that are used to things like Subversion... to do a "commit" in the old sense of the word (i.e. -- or in git speak -- to add, commit, and push) in a single step I generally add something like the following in the root of my project (as a bat file in windows e.g. git-commit.bat). Then when I want to add, commit, and push I just type something like git-commit "Added some new stuff"
and it all goes to the remote repo.
Also, this way anyone on the project can use the same with out having to change anything locally.
I usually also run git config credential.helper store
once so I don't need to give uid/pwd when this is run.
::
:: add, commit, and push to git
::
@echo off
echo.
echo.
echo
echo Doing commit...
git add -A && git commit -m %1
echo.
echo.
echo Doing push...
git push
echo.
echo.
echo Done.
echo.
On my windows machine I have set up this .bashrc
alias to make the entire process more simple.
.bashrc
- refer SO threadadd the following line to file
alias gacp='echo "enter commit message : " && read MSG && git add . && git commit -m "$MSG" && git push'
it does git add commit and push . tweak it in any manner, say you don't want the push command remove that part
reload .bashrc
/ close and reopen your shell
gacp
command .You ca use -a
git commit -h
...
Commit contents options
-a, -all commit all changed files
...
git commit -a # It will add all files and also will open your default text editor.