Skip to main content

Git Undo Last Commit: reset –soft, –hard, revert and amend (With Pushed Commits)

Undo the last Git commit safely: amend, reset –soft/–mixed/–hard, recovering with reflog, revert for pushed commits, and –force-with-lease when you must rewrite. Every command was run on a real repository, with a script to reproduce each transcript.

Everyone who has used Git for long enough has committed something they did not mean to — a debug print left in, a config file with the wrong values, a message that just says “wip”. The fix depends on one question before anything else: has that commit left your machine yet? If not, you can rewrite it freely. If it has, other people may already be building on it, and the safe tools are different.

This page starts from zero and goes in one direction. First the mental model, then the local fixes (amend and the three kinds of reset), then how to get a “deleted” commit back, then the pushed case (revert, and when --force-with-lease is acceptable). Every command was run on a real repository and the output is pasted from that run. It is the twelfth post in this site’s Git command guide, following Git Log.

The short answer. Not pushed, and you want the changes back to edit: git reset --soft HEAD~1. Not pushed, and you want them gone: git reset --hard HEAD~1. Only the message is wrong, or a file is missing: git commit --amend. Already pushed and anyone else might have it: git revert HEAD, then push normally.
Tested with Git 2.43.0 on Linux, 9 November 2026. Every transcript below comes from one script, git-undo-last-commit-demo.sh, which builds throwaway repositories in a temporary directory and deletes them when it exits. Commit timestamps are pinned, so if you run it your hashes should match the ones printed here. Sections marked with a triangle expand for the deeper material.

Pick the undo by asking whether the commit was pushed

There are five tools in this post and they are easy to confuse because they all “undo a commit”. They differ in what they touch. amend and reset rewrite history: the commit you made is replaced or abandoned. revert adds history: a new commit cancels the old one. Rewriting is harmless on a commit nobody else has seen and disruptive on one they have, which is why the first question is about pushing, not about which command you remember.

Has the commit left your machine?no, local onlyyes, pushed or sharedWhat is wrong with it?Does anyone else use this branch?Wrong message, or a forgotten filegit commit –amendRight changes, wrong commitgit reset –soft HEAD~1Throw the changes awaygit reset –hard HEAD~1Yes, or you are not suregit revert HEAD, then git pushOnly mine: reset or amend, thengit push –force-with-leaseUnsure whether anyone pulled it? Choose revert. It is safe whether or not they did.Local commits are free to rewrite. Pushed commits are a promise to everyone who fetched them.

Start at the top and follow the answers. The left branch is the comfortable one: three local tools, each for a different complaint. The right branch is where care matters, and the default there is revert. The amber box is the exception, not the rule — rewriting a pushed branch is only for a branch that is yours alone, and even then you push with --force-with-lease, never a bare --force. Both are explained in their own sections below.

What you wantCommandRewrites history?OK after you pushed?
Fix the message or add a forgotten filegit commit --amendYesOnly with a lease push on your own branch
Un-commit, keep changes stagedgit reset --soft HEAD~1YesOnly with a lease push on your own branch
Un-commit, keep changes unstagedgit reset HEAD~1YesOnly with a lease push on your own branch
Un-commit and delete the changesgit reset --hard HEAD~1YesOnly with a lease push on your own branch
Cancel a commit without touching historygit revert HEADNoYes, this is what it is for
Going deeper: where the official docs draw the same line

A commit is a snapshot, and a branch is a movable label pointing at one

The whole topic gets simpler once you see what “the last commit” physically is. Each commit is a snapshot that remembers its parent. A branch such as main is just a small label that points at one commit, and HEAD is the note that says which branch you are on. Making a commit moves the label forward by one. Resetting moves it backward. Nothing in that sentence deletes a snapshot.

Here is the repository used throughout this post: three commits, the last one being the mistake.

$ git log --oneline
855a3ff Add debug logging (oops)
5b9afb8 Fix pagination bug
f8fd98e Add search endpoint
$ git status -sb
## main

Transcript from git-undo-last-commit-demo.sh, step 01.

Beforef8fd98e5b9afb8855a3ffmain (HEAD)After git reset –soft HEAD~1f8fd98e5b9afb8855a3ffmain (HEAD)855a3ff still exists, but no branch points at it

The diagram shows the single most important fact about reset. After the label moves back, commit 855a3ff is not erased; it is simply unreachable from any branch, so it stops appearing in git log. It lives on in the object database until Git’s garbage collection eventually prunes it, which is exactly why the recovery section further down works.

HEAD~1 means “one commit before HEAD”, so HEAD~1 from the tip is the commit before your mistake. HEAD~2 would be two back, and you can also give a hash directly (git reset --soft <hash> moves the label to that commit and abandons everything after it).

Going deeper: the three areas Git keeps, and why reset has three modes

Git tracks three things at once: the branch pointer (the committed history), the staging area or index (what the next commit will contain), and your working files (what is actually on disk). git status is the command that compares them — see Git Status for reading its output. The three reset modes differ only in how many of the three areas they rewind, which is the next section’s table.

If you have not pushed, git reset moves the label back and you choose what happens to the changes

When the bad commit only exists locally, git reset removes it cleanly. The three modes differ in what they do with the changes that were inside the commit. Start with --soft, the gentlest: it moves the branch back but leaves every changed file staged, exactly as if you had just run git add on them. I reach for it when the content of the commit was fine but I want to fold it into the next commit, split it up, or fix the message.

$ git reset --soft HEAD~1
$ git status -sb
## main
M  a.txt
A  debug.cfg
$ git log --oneline
5b9afb8 Fix pagination bug
f8fd98e Add search endpoint

Transcript from git-undo-last-commit-demo.sh, step 02.

Read the git status -sb output as a two-column code: the first column is the staging area, the second is the working files. M  a.txt and A  debug.cfg mean both changes are staged and ready to commit again. The log has lost its top line.

The default mode, --mixed, goes one step further: it also empties the staging area, so the same changes become ordinary unstaged edits. You get it by omitting the flag.

$ git reset HEAD~1
Unstaged changes after reset:
M	a.txt
$ git status -sb
## main
 M a.txt
?? debug.cfg
$ git log --oneline
5b9afb8 Fix pagination bug
f8fd98e Add search endpoint

Transcript from git-undo-last-commit-demo.sh, step 03.

Notice debug.cfg now shows as ??, untracked: it was added by the undone commit, so once it is un-staged Git no longer knows about it. The file itself is still on disk. I use --mixed less often than --soft or --hard because I rarely want changes half-staged, but it is the default and worth recognising.

Branch pointerStaging areaYour filesgit reset –softmoved backunchangedunchangedgit reset –mixedmoved backreset to matchunchangedgit reset –hardmoved backreset to matchreset to matchRead left to right: –soft stops after moving the pointer, –mixed also rewrites the staging area, –hard rewrites your files too.

The grid is the whole difference between the three modes. All three move the branch pointer; the columns to the right show how far each one reaches. The original comparison, in table form:

ModeMoves branch pointerStaging areaWorking directory
--softYesUnchanged — changes stay stagedUnchanged — files untouched
--mixed (default)YesReset — changes become unstagedUnchanged — files keep their edits
--hardYesResetReset — all changes discarded

Finally --hard, for when you want the commit’s changes gone entirely — not staged, not on disk. This is the one to be careful with: there is no staging step and no working-copy step, the changes are discarded immediately. Notice that the untracked file notes.txt survives, because Git never knew about it.

$ git reset --hard HEAD~1
HEAD is now at 5b9afb8 Fix pagination bug
$ git status -sb
## main
?? notes.txt
$ git log --oneline
5b9afb8 Fix pagination bug
f8fd98e Add search endpoint

Transcript from git-undo-last-commit-demo.sh, step 04.

--hard also destroys edits you had not committed yet — and the reflog cannot bring those back. The next transcript has an uncommitted line in a.txt. After git reset --hard HEAD~1 the status is clean and the line is gone. The reflog only records commits; a change that was never committed was never recorded. If you have uncommitted work you care about, commit it or git stash it first, or use --keep (below).
$ git status -sb
## main
 M a.txt
$ git reset --hard HEAD~1
HEAD is now at 5b9afb8 Fix pagination bug
$ git status -sb
## main
$ cat a.txt
one
two

Transcript from git-undo-last-commit-demo.sh, step 14.

Going deeper: git reset --keep, the safer hard reset

--keep resets like --hard but refuses to run if it would overwrite your uncommitted work, so it fails loudly instead of silently eating edits. In the first transcript the commit being undone touched a.txt and so did my uncommitted edit, so Git stops. In the second the uncommitted edit is in a different file from the one the bad commit changed, so it goes through and my edit survives.

$ git reset --keep HEAD~1
error: Entry 'a.txt' not uptodate. Cannot merge.
fatal: Could not reset index file to revision 'HEAD~1'.
$ git status -sb
## main
 M a.txt

Transcript from git-undo-last-commit-demo.sh, step 15.

$ git status -sb
## main
 M a.txt
$ git reset --keep HEAD~1
$ git status -sb
## main
 M a.txt
$ cat a.txt
a
my unsaved work

Transcript from git-undo-last-commit-demo.sh, step 16.

Reference: git reset –keep.

Going deeper: undoing the very first commit of a repository

HEAD~1 means “the parent of HEAD”, and the first commit has no parent, so the usual command fails. The way out is to delete the branch’s ref with git update-ref -d HEAD, which leaves the files staged on a branch with no commits yet.

$ git reset --soft HEAD~1
fatal: ambiguous argument 'HEAD~1': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
$ git update-ref -d HEAD
$ git status -sb
## No commits yet on main
A  f

Transcript from git-undo-last-commit-demo.sh, step 09.

If you reset too far, the reflog remembers where HEAD used to be

Because reset only moves a label, you can move it back — provided you can find the old position. Git keeps a private diary of every place HEAD has pointed, called the reflog. Here a --hard reset throws away the commit, then the reflog shows it still exists as HEAD@{1}, and a second reset restores it.

$ git reset --hard HEAD~1
HEAD is now at 5b9afb8 Fix pagination bug
$ git reflog
5b9afb8 HEAD@{0}: reset: moving to HEAD~1
855a3ff HEAD@{1}: commit: Add debug logging (oops)
5b9afb8 HEAD@{2}: commit: Fix pagination bug
f8fd98e HEAD@{3}: commit (initial): Add search endpoint
$ git reset --hard HEAD@{1}
HEAD is now at 855a3ff Add debug logging (oops)
$ git log --oneline
855a3ff Add debug logging (oops)
5b9afb8 Fix pagination bug
f8fd98e Add search endpoint

Transcript from git-undo-last-commit-demo.sh, step 05.

Two details worth reading in that output. The reflog lists newest first, so HEAD@{0} is where you are now and HEAD@{1} is where you were one move ago. And the second reset fully restored the commit — same hash 855a3ff, same history. Nothing was ever lost, only unlabelled.

There is a shortcut for the most common case. Git also sets a ref called ORIG_HEAD to where HEAD was before a risky operation like reset, so “undo my reset” is one command:

$ git reset --hard HEAD~1
HEAD is now at 5b9afb8 Fix pagination bug
$ git rev-parse --short ORIG_HEAD
855a3ff
$ git reset --hard ORIG_HEAD
HEAD is now at 855a3ff Add debug logging (oops)
$ git log --oneline -1
855a3ff Add debug logging (oops)

Transcript from git-undo-last-commit-demo.sh, step 06.

Recovery has a time limit, and it is shorter for the commit you most want back. Reflog entries for commits still reachable from a branch expire after 90 days by default. Entries for commits that are not reachable — exactly what a reset leaves behind — expire after 30. Git does not delete them the moment they expire, only when garbage collection next runs, so the window can be longer in practice but should not be relied on.
Going deeper: where the 30 and 90 day numbers come from

They are the defaults of two settings, gc.reflogExpire (90 days) and gc.reflogExpireUnreachable (30 days). On a machine where neither is set, asking Git shows no value, meaning the built-in default applies.

$ git config --get gc.reflogExpire || echo "(unset: default 90 days)"
(unset: default 90 days)
$ git config --get gc.reflogExpireUnreachable || echo "(unset: default 30 days)"
(unset: default 30 days)

Transcript from git-undo-last-commit-demo.sh, step 21.

One correction to a habit: git checkout <hash> on a lost commit only puts you on it with a detached HEAD; it does not put your branch back. To restore the branch use git reset --hard <hash>, or keep the commit under a name with git branch rescue <hash>. See Git Checkout for detached HEAD.

If only the message or one file is wrong, git commit --amend replaces the commit

Often the changes are right and you just wrote a bad message or forgot to git add a file. Resetting is overkill. --amend builds a new commit to replace the last one, using whatever is currently staged plus the old content.

$ git commit --amend -m "Add request logging"
[main 3465bea] Add request logging
 Date: Thu Jan 1 00:00:00 2026 +0000
 2 files changed, 2 insertions(+)
 create mode 100644 debug.cfg
$ git log --oneline
3465bea Add request logging
5b9afb8 Fix pagination bug
f8fd98e Add search endpoint

Transcript from git-undo-last-commit-demo.sh, step 07.

Look at the hashes: the old commit was 855a3ff, the amended one is 3465bea, and the log shows the old one gone. That is the key fact about amend — it does not edit a commit, it replaces it with a different one. That is also why amending a commit you have already pushed is a history rewrite, covered in the force-push section.

To add a forgotten file, stage it and amend without changing the message:

$ git commit --amend --no-edit
[main 0c7f6d8] Add debug logging (oops)
 Date: Thu Jan 1 00:00:00 2026 +0000
 3 files changed, 3 insertions(+)
 create mode 100644 debug.cfg
 create mode 100644 forgot.txt
$ git show --stat --oneline HEAD
0c7f6d8 Add debug logging (oops)
 a.txt      | 1 +
 debug.cfg  | 1 +
 forgot.txt | 1 +
 3 files changed, 3 insertions(+)

Transcript from git-undo-last-commit-demo.sh, step 08.

Going deeper: amend options and editor behaviour
  • --no-edit keeps the existing message without opening your editor (used above).
  • Without -m or --no-edit, Git opens your editor with the old message so you can change it.
  • In these transcripts the editor is replaced with a no-op (GIT_EDITOR=true) so the script can run unattended.

Reference: git commit –amend.

If you have already pushed, git revert adds a commit that cancels the bad one

git reset rewrites history by moving the branch pointer backward, which is fine on a commit only you have ever seen. Once you have pushed and someone else might have pulled it, rewriting history under them causes exactly the divergent-history mess covered in Git Pull. For pushed commits, use git revert instead: it creates a new commit that undoes the changes, leaving history intact and forward-only.

f8fd98eAdd search endpoint5b9afb8Fix pagination bug855a3ffAdd debug logging4b2b7c0Revert 855a3ffmain (HEAD)Nothing is removed. One commit is added whose changes are the exact opposite of 855a3ff.Everyone who already has 855a3ff can fast-forward to 4b2b7c0 with an ordinary pull.

The diagram is the reason revert is safe. Everyone who already has 855a3ff keeps it, and the new commit simply sits on top, so their next pull is an ordinary fast-forward. Here it is for real:

$ git revert --no-edit HEAD
[main 4b2b7c0] Revert "Add debug logging (oops)"
 Date: Thu Jan 1 00:00:00 2026 +0000
 2 files changed, 2 deletions(-)
 delete mode 100644 debug.cfg
$ git log --oneline
4b2b7c0 Revert "Add debug logging (oops)"
855a3ff Add debug logging (oops)
5b9afb8 Fix pagination bug
f8fd98e Add search endpoint
$ git status -sb
## main

Transcript from git-undo-last-commit-demo.sh, step 10.

The log afterwards shows both commits — the original mistake and the revert that undoes it — and the working tree is clean. Then push the revert like any other commit with git push origin main (see Git Push). This is the part that surprised me the first time I used revert: it does not remove the bad commit from history, it adds a new one on top. Anyone reading the log later sees both the mistake and the fix, which is a more honest record than rewriting things to look like the mistake never happened.

Reverting does not un-publish what was in the commit. If the bad commit contained a password, API key or token, the old commit is still in history and still in every clone that fetched it. Treat the secret as leaked: rotate it first, clean up second.
Going deeper: reverting a commit from the middle of history

git revert <hash> works on any commit, not only the latest. When nothing later touched the same lines, it is clean:

$ git revert --no-edit HEAD~1
[main fd3217c] Revert "Add debug logging (oops)"
 Date: Thu Jan 1 00:00:00 2026 +0000
 2 files changed, 2 deletions(-)
 delete mode 100644 debug.cfg
$ git log --oneline
fd3217c Revert "Add debug logging (oops)"
c350e13 Add feature X
855a3ff Add debug logging (oops)
5b9afb8 Fix pagination bug
f8fd98e Add search endpoint

Transcript from git-undo-last-commit-demo.sh, step 12.

While writing this post the more interesting case turned up. If a later commit changed the same lines, the revert conflicts. Git stops halfway, marks the file as unmerged (UU), and offers three exits: fix the file and git revert --continue, git revert --skip, or git revert --abort to return to where you started. The transcript uses --abort.

$ git revert --no-edit HEAD~1
Auto-merging a.txt
CONFLICT (content): Merge conflict in a.txt
error: could not revert 855a3ff... Add debug logging (oops)
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git revert --continue".
hint: You can instead skip this commit with "git revert --skip".
hint: To abort and get back to the state before "git revert",
hint: run "git revert --abort".
$ git status -sb
## main
UU a.txt
D  debug.cfg
$ git revert --abort
$ git status -sb
## main

Transcript from git-undo-last-commit-demo.sh, step 11.

Going deeper: reverting a merge commit needs -m, and has a trap

A merge commit has two parents, so Git cannot know which side you want to keep. You must say which parent is the mainline: -m 1 means “keep the first parent”, which on a merge into main is main’s own history.

$ git revert --no-edit HEAD
error: commit 9b4997b991ca5a44b36ef9fa887b7ae7c37ec7b0 is a merge but no -m option was given.
fatal: revert failed
$ git revert --no-edit -m 1 HEAD
[main 4855e98] Revert "Merge feature"
 Date: Thu Jan 1 00:00:00 2026 +0000
 1 file changed, 1 deletion(-)
 delete mode 100644 feat.txt
$ git log --oneline --graph
* 4855e98 Revert "Merge feature"
*   9b4997b Merge feature
|\  
| * 0e9f784 feature work
|/  
* 855a3ff Add debug logging (oops)
* 5b9afb8 Fix pagination bug
* f8fd98e Add search endpoint
$ git merge feature
Already up to date.

Transcript from git-undo-last-commit-demo.sh, step 13.

The last line is the trap. After the revert, Git still considers feature already merged, so merging it again does nothing. If you later want the feature back, the commonly documented route is to revert the revert commit; the Git project describes the full reasoning in its revert-a-faulty-merge how-to. I have not run that second step in this post’s script, so check it on a scratch repository before relying on it.

If you must erase a pushed commit, rewrite it and push with --force-with-lease

Sometimes revert is the wrong shape. The commit is on your own feature branch, nobody has built on it, and a clean history matters for the pull request. Then it is reasonable to reset or amend locally and replace the remote branch. First, notice that Git will not let you do it with an ordinary push, and that is protection, not a bug:

$ git push origin main
To ../remote.git
 ! [rejected]        main -> main (non-fast-forward)
error: failed to push some refs to '../remote.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. If you want to integrate the remote changes,
hint: use 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

After reset --hard HEAD~1 the local branch is one commit behind the remote. Transcript from git-undo-last-commit-demo.sh, step 20.

The rejection says non-fast-forward: your branch is no longer a descendant of what the remote has. Notice that reset alone changed nothing on the server — the remote only changes when you push. The hint suggests git pull, which would merge the bad commit straight back; ignore it here.

To replace the remote branch you have to force the push. The careful way is --force-with-lease: “overwrite the remote branch, but only if it is still exactly what I last fetched”.

$ git status -sb
## main...origin/main [behind 1]
$ git push --force-with-lease origin main
To ../remote.git
 + ad4553d...5ba9323 main -> main (forced update)
$ git log --oneline origin/main
5ba9323 base

Transcript from git-undo-last-commit-demo.sh, step 17.

That status line, [behind 1], looks alarming but is expected: you deliberately removed a commit the remote still has, so Git describes your branch as behind. The push then succeeds with forced update, and the remote log no longer has the bad commit. Now the case the lease exists for: a teammate pushed on top of your bad commit while you were resetting.

You say: only overwrite if the remote branch is still ad4553d, the one I last fetched.Remote branch is still ad4553dExpected value matches, so the push is allowed+ ad4553d…5ba9323 (forced update)Remote branch moved to 3ce1dcfA teammate pushed after you last fetched! [rejected] (stale info)Plain –force skips the comparison. In step 19 it replaced 3ce1dcf with 5ba9323,and the teammate’s commit vanished from the remote.The lease is only as good as your last fetch: it compares against what your cloneremembers, not what is on the server right now.
$ git push --force-with-lease origin main
To ../remote.git
 ! [rejected]        main -> main (stale info)
error: failed to push some refs to '../remote.git'
$ git fetch origin
From ../remote
   ad4553d..3ce1dcf  main       -> origin/main
$ git log --oneline origin/main
3ce1dcf Teammate work
ad4553d Bad commit
5ba9323 base

Transcript from git-undo-last-commit-demo.sh, step 18.

The lease refused with stale info: the remote had moved to 3ce1dcf while your clone still believed it was at ad4553d. After a fetch, the log shows what you would have destroyed — the teammate’s commit. That is the value of the lease. Compare what a bare --force does in the same situation:

$ git push --force origin main
To ../remote.git
 + 3ce1dcf...5ba9323 main -> main (forced update)
$ git --git-dir=../remote.git log --oneline main
5ba9323 base

Transcript from git-undo-last-commit-demo.sh, step 19.

The push reports forced update, and the remote log is back to base. The commit titled “Teammate work” is gone from the server. Their clone still has it, but your push has just made their next pull fail and their work homeless.

The lease is only as good as your last fetch. It compares against the remote-tracking ref in your clone. If something fetches in the background (an editor or IDE with auto-fetch, say), that ref updates to include your teammate’s commit without you having looked at it, and a bare --force-with-lease will then pass. Git documents this and offers --force-if-includes, which additionally checks that you have integrated what you fetched. Pair them: git push --force-with-lease --force-if-includes.
Going deeper: when a force push is simply not allowed, and the + shortcut
  • Many hosts let you protect a branch so that force pushes are rejected outright, which is the right setting for main. In that case revert is your only option, and that is by design. Check your host’s branch-protection settings for the exact behaviour.
  • git push origin +main is shorthand for forcing one branch; the leading + on a refspec has the same effect as --force for that ref, so it carries the same risk as step 19.
  • Tell the people who share the branch before you rewrite it. After a rewrite they need to reset their local copy to the new remote branch rather than pull.

Reference: git push, including –force-with-lease and –force-if-includes.

FAQs

I ran git reset –hard and need that commit back. Is it gone forever?

Probably not, if the commit was ever committed. Run git reflog, find the hash from before the reset, and restore it with git reset --hard <hash>, or just git reset --hard ORIG_HEAD if you have not done anything since. Unreachable commits survive for roughly 30 days by default, but do not rely on it. If what you lost was uncommitted edits, the reflog cannot help — see the red callout in the reset section.

Can I undo a commit from the middle of my history, not just the last one?

For an unpushed commit, an interactive rebase (git rebase -i) lets you drop a specific commit anywhere in the range. For a pushed commit, git revert <commit-hash> works on any commit, not just HEAD, though it can conflict if later commits touched the same lines.

What is the difference between git reset and git revert in one sentence?

reset moves your branch backward and rewrites history; revert adds a new commit that cancels out an earlier one without rewriting anything.

Does git reset change the remote repository?

No. It only moves your local branch. The remote changes when you push, and as shown in the force-push section, Git rejects a normal push after a reset because your branch no longer descends from the remote one.

I committed a password. Is reverting enough?

No. A revert hides the secret in the latest snapshot but it stays in history and in every clone that already fetched it. Rotate the credential first. Rewriting history to remove it is a separate, heavier job and still does not recall copies others already have.

Should you rewrite history at all?

Usually you should not, once it is pushed. Rewriting is a good habit for local commits and a poor one for shared branches. The rule I actually follow: if the remote-tracking branch shows my commit has not been pushed yet, reset is fair game. The moment it is pushed, I treat history as fixed and reach for revert instead, no exceptions, even on branches nobody else seems to be using — “nobody else is using it” has been wrong for me before. The one place I make an exception is a short-lived feature branch that is mine alone, and there I use --force-with-lease, never plain --force.

Further reading

See Also: This Site’s Git Command Guide

This post is part of a 13-part Git command guide on this site:

Conclusion

One question does most of the work: has the commit been pushed? If not, amend or reset and move on, and remember the reflog if you overshoot. If it has, revert. Last stop in this guide is a smaller but genuinely useful one: Git – Autocorrect Spelling.

No Comments yet!

This site uses Akismet to reduce spam. Learn how your comment data is processed.