Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Modify commit

apaksoy January 25, 2015

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
Balázs Szakmáry
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 25, 2015

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.)

 

apaksoy January 25, 2015

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

Balázs Szakmáry
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 25, 2015

Yes, I updated the answer accordingly.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events