Posted By

alvarezrilla on 03/16/10


Tagged

git amend


Versions (?)

Git: Remove file accidentally added to the repository.


 / Published in: Bash
 

URL: http://stackoverflow.com/questions/307828/git-remove-file-accidentally-added-to-the-repository

Note that you don't actually need a temporary branch, you can do this with a 'detached HEAD', but you need to take a note of the commit id generated by the git commit --amend step to supply to the git rebase command rather than using the temporary branch name.

  1. # create and check out a temporary branch at the location of the bad merge
  2. git checkout -b tmpfix <sha1-of-merge>
  3.  
  4. # remove the incorrectly added file
  5. git rm somefile.orig
  6.  
  7. # commit the amended merge
  8. git commit --amend
  9.  
  10. # go back to the master branch
  11. git checkout master
  12.  
  13. # replant the master branch onto the corrected merge
  14. git rebase tmpfix
  15.  
  16. # delete the temporary branch
  17. git branch -d tmpfix

Report this snippet  

You need to login to post a comment.