I pushed a commit to a repo where I accidentally added a file. Nobody else has merged from the remote repo so I can rewrite history. But when I remove file(unstage, not remove f
Here you go:
git checkout HEAD~ -- path/to/your/file
git add path/to/your/file
git commit --amend -C HEAD
git diff -p HEAD~ -- path/to/your/file | git apply -R
git commit --amend -C HEAD
git reset HEAD~ -- path/to/your/file
git commit --amend -C HEAD
Try:
git rm --cached <yourfile>
git commit --amend
git push -f
While I did something similar to what Colin and ydroneaud have suggested,
The answer was to use
git push +sa1:sa1
where sa1 is my branch. This forces to push even 'nothing'.
If you need to rewrite the full commit, try to use
git reset HEAD^
git add <files to be part of the commit>
# or git add -pu
git commit -C <previous commit number>
Before doing this you will need to keep the last commit number to able to reuse the commit message/date/author.