Git add and commit in one command

后端 未结 27 2374
旧巷少年郎
旧巷少年郎 2020-11-28 00:28

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,

27条回答
  •  春和景丽
    2020-11-28 00:38

    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.
    

提交回复
热议问题