Return to Snippet

Revision: 24928
at March 16, 2010 07:35 by alvarezrilla


Initial Code
# create and check out a temporary branch at the location of the bad merge
git checkout -b tmpfix <sha1-of-merge>

# remove the incorrectly added file
git rm somefile.orig

# commit the amended merge
git commit --amend

# go back to the master branch
git checkout master

# replant the master branch onto the corrected merge
git rebase tmpfix

# delete the temporary branch
git branch -d tmpfix

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

Initial Description
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.

Initial Title
Git: Remove file accidentally added to the repository.

Initial Tags
git

Initial Language
Bash