Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+6 votes
2 views
in DevOps and Agile by (29.3k points)
edited by

I am using Git and I have committed few files using

git commit -a

Later, I found that a file had mistakenly been added to the commit.

How can I remove a file from the last commit?

closed

1 Answer

+8 votes
by (50.2k points)
selected by
 
Best answer

Moving the mistakenly committed files back to the staging area from the previous commit, without canceling the changes done to them. This can be done by using

 git reset --soft HEAD^ 

or

git reset --soft HEAD~1

To leave that unwanted file just reset it using

git reset HEAD path/to/unwanted_file

Now you can commit those files

git commit -c ORIG-HEAD

Note: you can give the same commit message also.

Related questions

0 votes
1 answer
+2 votes
1 answer
+2 votes
1 answer
0 votes
1 answer
asked Nov 4, 2019 in DevOps and Agile by chandra (29.3k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...