This may sound weird, but I just amended a commit to test my EDITOR
environment variable. I wasn't aware that the commit would be amended even though I didn't edit the commit message or any files. The commit in question was merged from the develop branch into the master branch and tagged. After the amend though, the branch structure went all wonky:
I don't know how bad this is or how many issues it will cause in the future, but I don't dare touch the repository until I know more. I'd really like to just rewind the repository back to before I amended the "Added docs." commit. The develop branch should be pointing to the "Added docs." commit that's merged into the master branch, and the current "Added docs." commit should not exist.
Is that possible?
Related:
The git reset and revert commands are commonly confused, but they apply to distinct use cases. To undo changes associated with a specific commit, developers should use the git revert command. To undo every change that has happened since a given commit occurred, use git reset.
If you delete the commit message (no need to delete the ones starting with # ) you will abort the git commit --amend command. You will get output like this: Aborting commit due to empty commit message. Save this answer.
Use git reset if the commit is not pushed yet and you don't want to introduce a bad commit to the remote branch. Use git revert to revert a merge commit that has already pushed to the remote branch. Use git log to review the commit history. If you prefer, you can also create a new commit with the fix.
You should be able to do a
git reflog
Then find out the commit you were in before your “commit --amend”. Usually this would be HEAD@{1}. Now do a
git reset --soft HEAD@{1}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With