Remove 1 file from commit, keep changes locally.

jmejiaa1986 March 26, 2014

I went ahead and did a commit of multiple files, my intentions of course to push later.

One of these files I can't send to the server, so I want to remove it from my commit BUT I want to keep the changes I have in this file.. So I want to remove the commit but keep this version in my working copy..

Does this make sense? I'm not sure what to do and I just had a big scare and thought I had lost all my work :/

2 answers

1 vote
Sumali March 26, 2014

Easiest way assuming you haven't pushed yet and the file was a brand new file that was added in your last commit:

  1. back up your entire local working copy in case I'm wrong...
  2. go to "Working Copy" view and "show all" files
  3. right click on the file and select "Stop Tracking", you will now see the file appear as an untracked file in your working tree and a deleted file in your staging area
  4. press the commit button and select "amend latest commit" and go ahead and commit this change - (this step relies on the fact that the commit where you added the file was the last commit)

Now your commit history shouldn't contain the file but it should still be sitting in your working copy intact and waiting to be committed as an untracked file.

0 votes
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.
March 26, 2014

Sumali's answer is great. In case his assumption that the file is "new" is incorrect, you can do something very similar (Full credit to Sumali for steps 1 and 4, which I copied verbatim):

  1. back up your entire local working copy
  2. view the commit in the log view
  3. click the file in the changed files list, then click the "Reverse File" button at the top of the diff
  4. press the commit button and select "amend latest commit" and go ahead and commit this change - (this step relies on the fact that the commit where you added the file was the last commit)
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.
March 26, 2014

You will have to restore the file in question from your backup.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events