How to change past commit to include a missed file?

后端 未结 4 923
日久生厌
日久生厌 2021-01-29 23:02

I have committed a change and forgot to add a file to the change set. After other commits, I realized the file is now missing from a HEAD^4 commit.

How do I

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-29 23:51

    I realize people can google and come here to find a simpler answer: What if it was just the last commit? (OP's question is for fixing the 4th commit back in history)

    In the case you commit and realize you forgot to add some file immediately, just do:

    # edited file-that-i-remember.txt
    git add file-that-i-remember.txt
    git commit
    
    # realize you forgot a file
    git add file-that-i-forgot.txt
    git commit --amend --no-edit
    

    Where --no-edit will keep the same commit message.

    Easy peasy!

提交回复
热议问题