0

I have added two new files to my commit, and deleted them after commiting to my local repo , how can delete those files from the same commit.

Sirish
  • 9,183
  • 22
  • 72
  • 107

2 Answers2

2

I'm assuming you did the following:

//Created files A.txt and B.txt
git add A.txt
git add B.txt
git commit -m "Commit message"

Now you want that the previous commit didn't have the two files A.txt and B.txt, so you can do:

git rm A.txt
git rm B.txt
git commit --amend

But remember, if you PUSHED that commit, DON'T AMEND, instead, create a new commit that deletes the two files.

Mark Longair
  • 446,582
  • 72
  • 411
  • 327
Gustavo Muenz
  • 9,278
  • 7
  • 40
  • 42
1

git reset --soft HEAD^

This will undo your last commit and put your repo in the state right before you did the last commit. From here you can unstage and undo add/delete of files etc.

rtn
  • 127,556
  • 20
  • 111
  • 121