How can I unstage my files again after making a local commit?

前端 未结 7 860
灰色年华
灰色年华 2020-12-22 16:16

I have executed the following command

git add 
git commit -m \"add the foo.java file\"

How can I delete my local commit now

7条回答
  •  清歌不尽
    2020-12-22 16:27

    git reset --soft HEAD~1 should do what you want. After this, you'll have the first changes in the index (visible with git diff --cached), and your newest changes not staged. git status will then look like this:

    # On branch master
    # Changes to be committed:
    #   (use "git reset HEAD ..." to unstage)
    #
    #       modified:   foo.java
    #
    # Changes not staged for commit:
    #   (use "git add ..." to update what will be committed)
    #   (use "git checkout -- ..." to discard changes in working directory)
    #
    #       modified:   foo.java
    #
    

    You can then do git add foo.java and commit both changes at once.

提交回复
热议问题