How to modify a specified commit?

后端 未结 16 1298
清酒与你
清酒与你 2020-11-22 01:53

I usually submit a list of commits for review. If I have the following commits:

  1. HEAD
  2. Commit3
  3. Commit2
16条回答
  •  清歌不尽
    2020-11-22 02:31

    Run:

    $ git rebase --interactive commit_hash^

    each ^ indicates how many commits back you want to edit, if it's only one (the commit hash that you specified), then you just add one ^.

    Using Vim you change the words pick to reword for the commits you want to change, save and quit(:wq). Then git will prompt you with each commit that you marked as reword so you can change the commit message.

    Each commit message you have to save and quit(:wq) to go to the next commit message

    If you want to exit without applying the changes, press :q!

    EDIT: to navigate in vim you use j to go up, k to go down, h to go left, and l to go right( all this in NORMAL mode, press ESC to go to NORMAL mode ). To edit a text, press i so that you enter the INSERT mode, where you insert text. Press ESC to go back to NORMAL mode :)

    UPDATE: Here's a great link from github listing How to undo (almost) anything with git

提交回复
热议问题