Git add and commit in one command

后端 未结 27 2251
旧巷少年郎
旧巷少年郎 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:47
    git commit -am "message"
    

    is an easy way to tell git to delete files you have deleted, but I generally don't recommend such catch-all workflows. Git commits should in best practice be fairly atomic and only affect a few files.

    git add .
    git commit -m "message"
    

    is an easy way to add all files new or modified. Also, the catch-all qualification applies. The above commands will not delete files deleted without the git rm command.

    git add app
    git commit -m "message"
    

    is an easy way to add all files to the index from a single dir, in this case the app dir.

    0 讨论(0)
  • 2020-11-28 00:48

    I hope this helps someone and please feel free to edit or improve. I'm not sure what the fastest way is but this certainly simplifies my code commit process by using "ohmyzsh" for Git.

    https://ohmyz.sh/

    • git add . is shortened to ga .
    • git commit -m "message" is shortened to gc -m "message"
    • git push is shortened to gp
    • git fetch is shortened to gf
    • git pull origin master is shortened to ggl master
    • git push origin master is shortened to ggp master
    • git checkout -b is shortened to gcb
    • git merge is shortened to gm
    • git remote is shortened to gr
    • git status is shortened to gst

    0 讨论(0)
  • 2020-11-28 00:49
    1. Create an alias in bash: alias gac="git add -A && git commit -m"

      (I chose to call the shortcut 'gac' but you don't have to)

    2. Use it: gac 'your commit message here'

    0 讨论(0)
  • 2020-11-28 00:49

    This works for me always please run following commands:

    1.git add .
    2.git commit -m "no bugs please"
    3.git push origin *
    

    where * is based off the branch you are pushing to, and also commit messages can always be changed to suit the context.

    0 讨论(0)
  • 2020-11-28 00:50

    Only adapting the Ales's answer and the courtsimas's comment for linux bash:

    To keep it in one line use:

    git commit -am "comment"

    This line will add and commit all changed to repository.

    Just make sure there aren't new files that git hasn't picked up yet. otherwise you'll need to use:

    git add . ; git commit -am "message"

    0 讨论(0)
  • 2020-11-28 00:50

    I use the following alias for add all and commit:

    git config --global alias.ac '!git add -A && git commit -a'
    

    Then, by typing:

    git ac
    

    I get a vim window to get more editing tools for my commit message.

    0 讨论(0)
提交回复
热议问题