Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove file from amended commit

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

like image 530
sa1 Avatar asked Apr 12 '12 13:04

sa1


People also ask

How do I remove a file from a modified list in git?

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.

How do you exclude a file from a commit?

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.

How do I edit an amended commit in git?

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.


2 Answers

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
like image 186
Colin Hebert Avatar answered Nov 13 '22 01:11

Colin Hebert


Try:

git rm --cached <yourfile>
git commit --amend
git push -f
like image 36
KurzedMetal Avatar answered Nov 13 '22 01:11

KurzedMetal