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

Jonas Bang Christensen February 20, 2014

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

0 votes
Answer accepted
Seth
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.
February 20, 2014

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.

Jonas Bang Christensen February 20, 2014

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

Seth
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.
February 20, 2014

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
TAGS
AUG Leaders

Atlassian Community Events