Commit hunks/staged files with sourcetree?

Scenario: While working on a task/feature, you fixed a small bug in an unrelated area of one of the files you changed. At commit, you'd like to commit that separately.

Tried staging the hunk I wanted to commit,
- There is no option to commit what is staged,

Tried staging what I didn't want to commit,
- Everything I'd staged also appeared in the commit anyway,

Tried discarding what I didn't want to commit,
- Actually removed/reverted the change from the source file.

So what is the intended workflow for cherry picking a subset of changes and commiting just them? Am I missing something obvious?

3 answers

Hi Oliver. Is this for Windows or Mac?

Hi, Kieran, Sorry for the delayed reply - it was for Windows but the pathalogical behavior went away and the workflow is now actually pretty nice -- one simply selects "Commit" from the button bar or on the "Uncomitted changes" view and then "stage hunk" or "stage selected lines", which automatically takes you into "Staged changes" view mode, and in that mode you can cherry pick hunks or individual lines to commit.

The only disadvantage to this right now is that when you "stage file" the view refreshes and resets the selected file to the top file in the list.

Lets say you just removed a #include from include/pch.h and you want to commit adding the include to the src/*.cpp files. This gets annoying, fast, because every time you "stage file" from a src file, it resets the current file to h/pch.h.

Hi Oliver,

Thanks very much for the insight. This sounds to me like you'd like it to behave in a different manner. If so, could you possible file a new issue on (project SRCTREEWIN) with as much detail as possible? Feature requests go there usually and they're reviewed periodically with feedback given and hopefully assigned to an issue.

Thanks very much

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,237 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