Kamiky
Kamiky

Reputation: 619

Remove last Github commit, without removing code in local repository

In my unity3d game project, I'm using Atlassian SourceTree for committing code to my Github repository. The last commit has wrong commit message, and I wanted to change commit message(as I googled, that's impossible). So the last chance for me is to revert the last commit and make a new one with the correct commit message. How could this be done using Atlassian SourceTree utility.

Upvotes: 0

Views: 418

Answers (2)

Roberto
Roberto

Reputation: 11953

If you already pushed to the remote, I'd advise to forget about it. It's dangerous to re-write git history that was pushed if you don't know git very well.

If you didn't push and you didn't create any other commits on the top of it, you can do as the other answer says and amend a new commit with your last commit.

To do it in SourceTree, unstage all changes that you may have and press the commit button (like if you were creating an empty commit). Then, in the message tab click in Commit Options and select Amend last commit. You should see your former message now, change it and commit.

Again, don't do it if you pushed this commit to the remote, don't use push --force.

push

Upvotes: 1

Fredrik
Fredrik

Reputation: 5108

Impossible? I think not!

Just open up a cmd, go to your project and write git commit --amend -m "your new message" and then git push --force. This will edit the last comment's commit message and then force push the branch to force your edit on history. (force push is necessary since you're manipulating history and will overwrite/force the remote branch to look like your local branch. Use with care if you're in a project with more people)

Upvotes: 2

Related Questions