Petr
Petr

Reputation: 14505

How to remove ignored files from current commit using git commit --amend

I made a commit which contains lot of .o files that I want to ignore. So I created a .gitignore file and even made it default global (I put it to my home and did git config --global core.excludesfile ~/.gitignore).

Now I need to amend that commit so that these files are no longer in it before I push. However doing just git commit -a --amend leave the ignored files in the commit.

I need to re-apply these new ignore rules on this existing commit before I push it

How do I fix it?

Upvotes: 1

Views: 304

Answers (1)

Agis
Agis

Reputation: 33666

Do a:

$ git reset --soft HEAD^

and you will see the changes you've made to that commit as staged. Now unstage the unwanted files and commit only the wanted ones:

$ git reset HEAD *.o
$ git commit -m "commit msg"

Upvotes: 3

Related Questions