Have you ever commit all file from your project. After that, you realize that threre is a file (or files) you are not ready to commit it. So, the problem is that you want to remove a file from last commit?

Here you can see in the image below. I have one commit and 2 new files.

remove file from commit 1

The problem comes when i commit both "file2" and "file3". And suppose that file3 is the file i don't want to commit

remove file from commit 2

Okey .Let's do some very simple stuff to remove "file3" from last commit.

NOTE: In this post, i use SourceTree. You can use other tool or use git command line

Step 1: Reset to last commit use "SOFT" option

remove file from commit 3

Step 2: Remove file (files) you don't want to commit.

You can see i've comeback to last commit and new files still there.

remove file from commit 4

Let's unstage file (files) you don't want to commit.

In this case, i remove "file3"

remove file from commit 5

Step 3: Commit

You can now re-commit without files you don't want.

 

DONE!

Please leave a comment to let me know that you successfully removed the unwanted files.

 

THANKS FOR READING MY POST!


Long Trương

Hi, i'm Long. Welcome to my personal blog. Hope that you can findout something helpful...

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *