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 from source control, or disk) from local commit, I am unable to push changes. git push shows Everything up-to-date
Using the git rm <file> --cached method While rm should be employed when removing files from your working directory, effectively erasing a file from existence, git rm will remove files or file modifications from the Git staging index.
Set “–assume-unchanged” to a path to exclude to check on git commit and it will exclude your file from git commit. You will need to use the git update-index and –assume-unchanged to exclude files from git commit.
Git has a solution for you: the git commit –amend command. You can use this command without the -m flag. If you do, an interactive text editor will be opened up in which you can replace the message from your older commit. Save and exit the text editor and your change will be made.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With