This is the 21st day of my participation in the November Gwen Challenge. Check out the event details: The last Gwen Challenge 2021

🤞 personal home page: @Qingcheng sequence member Stone 🤞 fan benefits: plus one to one fan group to answer questions, get free rich resume template, improve learning materials, do a good job in the new era of volume king!

Git commit git commit git commit git commit git commit git commit git commit In this article, the above mentioned content can be addressed.

First, the submission information is written wrong

If your commit message is incorrectly written and the commit has not yet been pushed, you can modify the commit message by using the following methods:

$ git commit --amend --only
Copy the code

This opens your default editor, where you can edit information. On the other hand, you can do it all at once with one command:

$ git commit --amend --only -m 'xxxxxxx'
Copy the code

If you have already pushed the commit, you can modify the commit and then force push, but this is strongly discouraged.

2. Delete any submitted content

It is possible that during a commit, you uploaded a file that should have been stored locally, such as the account and password, and you want to delete the record of this commit.

Same warning: Don’t do this unless you have to.

$ git rebase --onto SHA1_OF_BAD_COMMIT^ SHA1_OF_BAD_COMMIT
$ git push -f [remote] [branch]
Copy the code

Or do an interactive rebase to delete rows in the commit that you want to delete.

3, retrieve the content of reset hard operation

If you do git reset –hard by accident, you can usually get your commit back because Git keeps a log of everything and keeps it for a few days.

(main)$ git reflog
Copy the code

You’ll see a list of your past commits, and a reset commit. Select the SHA of the commit you want to return to and reset again:

(main)$ git reset --hard SHA1234
Copy the code

And you’re done.

Remove a file from a commit

Remove a file from a commit using the following method:

$ git checkout HEAD^ myfile
$ git add -A
$ git commit --amend
Copy the code

This can be very useful when you have an open patch and you commit an unnecessary file to it and you need to force push to update the remote patch.


Boy, haven’t you seen enough? Click on the details of the stone, casually have a look, maybe there is a surprise? Welcome to support the likes/attention/comments, your support is my biggest motivation, thank you!