Forgot to add file on old commit

Hello

I'm using SourceTree and I forgot to add a file to a previous commit - about 3 or 4 commits ago. How can I inlude this file in the desired commit?

2 answers

1 accepted

4 votes
Jeff Thomas Atlassian Team Nov 17, 2013

Hi Jesse,

You can use rebase to do this.

  1. Commit the files that you forgot to add
  2. Right-click on the parent commit of the commit you'd like to add the files to and click Select Rebase children of <SHA1> interactively...
  3. Use the arrows at the bottom to move the forgotten files commit so that it is above the commit you'd like to add them to
  4. Make sure the forgotten files commit is selected and click the Squash with previous button
  5. If you'd like, you can then edit the commit message with Edit message
  6. Select OK

Thanks for the reply Jeff. I should've specified this is a Windows install. I do not see Select Rebase children in the context menu. I can share a screen shot it you'd like.

Jeff Thomas Atlassian Team Nov 18, 2013

It looks like the Windows version does not support interactive rebasing (https://jira.atlassian.com/browse/SRCTREEWIN-405) yet. I don't know of another way to do this in SourceTree, but maybe someone else will.

You could also try to rebase with the command line - http://stackoverflow.com/a/2719636/1133218

Just a note to say that SourceTree for Windows does now support rebasing children interactively (I am using 1.6.10), so the above method now works.

Awesome. Thanks Jacqui!!

Looks like you can do it, at least in version 1.6.18.0 on Windows: Stage (add) your changes, as if you were going to perform a new commit. Then under "File Status" put your cursor into the Commit message box to open up the full commit pane. Top right choose from "commit options..." and select "Amend latest commit". You then get to copy the message from the previous commit into the message box, edit it if you want and commit. It performs a `git commit --amend` for you and voila - the previous commit is amended. Loverly.

Thanks I can confirm this (also) works great in v1.8.3 on Windows

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published May 30, 2018 in Sourcetree

Tip from the team: configuring Git or Mercurial in Sourcetree

Supported Platforms macOS Windows To make using Sourcetree as simple yet powerful as possible we embed (bundle) dependencies such as Git, Git LFS, and Mercurial. We strive to keep these...

570 views 1 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