Modify commit

Is there a way to modify an older commit(the files in that commit) without create a new commit?

1 answer

1 accepted

2 votes
Answer accepted

If the commit and at least on later one is already pushed to the server:

The short answer is "no".

The long answer is that it is possible to do this with Git (not SourceTree), but it is rather complicated and all the other users of the repository would find themselves with an incompatible version of the history that they would need to repair afterwards.

The best way to do this is to revert the commit you want to modify and create a new one with the right changes.


If the code is not pushed yet, which seems to be the case:

  1. (Stash any uncommitted changes you have.)
  2. Do a soft reset to the last commit before the commit you want to change. (Right-click on the commit you want to reset to and click the right option in the context menu.) Now all the changes made in the commits above this point are converted to uncommitted changes.
  3. Re-create the commit you wanted to edit and all the others after it.
  4. (Re-apply stashed changes and continue working.)


The commit is not pushed. Can it change the answer?

Yes, I updated the answer accordingly.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Oct 23, 2018 in Sourcetree

Tip from the team: configure your repos for hosting goodness!

Supported Platforms macOS Windows We recently introduced support for additional hosting services such as GitHub Enterprise, GitLab (Cloud, Community Edition, Enterprise Edition), and...

1,207 views 4 2
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you