How to amend a commit without changing commit message (reusing the previous one)?

拥有回忆 提交于 2019-11-26 10:05:14

问题


Is there a way to amend a commit without vi (or your $EDITOR) popping up with the option to modify your commit message, but simply reusing the previous message?


回答1:


Since git 1.7.9 version you can also use git commit --amend --no-edit to get your result.

Note that this will not include metadata from the other commit such as the timestamp which may or may not be important to you.




回答2:


git commit -C HEAD --amend will do what you want. The -C option takes the metadata from another commit.




回答3:


Another (silly) possibility is to git commit --amend <<< :wq if you've got vi(m) as $EDITOR.




回答4:


To extend on the accepted answer, you can also do:

git commit --amend --no-edit -a

to add the currently changed files.




回答5:


Using the accepted answer to create an alias

 oops = "!f(){ \
    git add -A; \
    if [ \"$1\" == '' ]; then \
        git commit --amend --no-edit; \
    else \
        git commit --amend \"$@\"; \
    fi;\
}; f"

then you can do

git oops

and it will add everything, and amend using the same message

or

git oops -m "new message"

to amend replacing the message



来源:https://stackoverflow.com/questions/10237071/how-to-amend-a-commit-without-changing-commit-message-reusing-the-previous-one

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!