How to remove a file from a commit using amend in SourceTree?

Use case:

I have committed a commit with 3 files in it. Now I want to amend that commit with only 2 of the 3 files in it, i.e. I want to remove 1 file from the commit.

Solution in Git GUI:

In "git gui", when selecting "Amend last commit", all the content of the commit gets listed in "Staged Changes" window, thus enabling the user to unstage files / lines before committing the new commit.

Problem in SourceTree:

When selecting "Amend latest commit" it does not list the content from the latest commit in the "Staged Changes" window, thus it is not possible to remove files / lines from the commit, only to add new files / lines to the commit.

Or am I missing some option?

Br,
Jonas

1 answer

1 accepted

If you want to undo part of the previous commit by amending, you should revert those changes in your working copy, and commit using the "amend last commit" option.

Seth, the commit amend workflow in SourceTree would then be:

1) Reverse commit
2) Reset soft
3) Commit amend (where you unstage the unwanted file)

The commit amend workflow in "git gui" is:

1) Commit amend (where you unstage the unwanted file)

The simple reason is that in "git gui" all content from latest commit is listed in "Staged Changes" window, SourceTree does not list those.

This has 2 negative impacts (in my mind):

1) When you do a commit amend in SourceTree (even if you are just adding stuff, not removing anything) you can not see the full list of changes which you are about to commit, only what you have added/changed on top of your commit. You basically don't know what you are committing, (unless you "reverse" and "reset" each time before a commit amend).
2) If you want to remove a file or change from a commit by amending it, you have to do a "reverse" and "reset" first. Or, click "Terminal" and fire up "git gui" ...

But yes, you have answered my question (though I already knew how to do this, was just puzzled about the fact that it was such a cumbersome process in SurceTree when I'm used to an easy one-step process in "git gui").

Just my 2 cent ... and hoping to see this native Git feature added to the SourceTree backlog ;o)

Br,
Jonas

You don't need to reverse the old commit. If you view the previous commit, you can reverse just specific chunks. These reversions are written to your working copy, not automatically committed.

In terms of the first negative impact, I'd rather see just what I'm changing from the previous commit, rather than a compliation of changes from both my working copy and the commit that's being amended. I guess that just comes down to personal preference.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Brian Ganninger
Published Jan 23, 2018 in Sourcetree

Tip from the team: workflow and keyboard shortcuts

Supported Platforms macOS Sourcetree has a lot to offer and, like many developer tools, finding and using it all can be a challenge, especially for a new user. Everyone might not love ...

649 views 0 4
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