I want to reset my repository but it is just unstaging

101 Views Asked by At

I had a repository with just one file 'file2.py' and is committed till now. Now I have created a new file file3.py and saved it . I staged the file using 'git add file3.py' Now i want to make my repository as it was in the latest commit that is before file3.py was created. I have used 'git reset HEAD file3.py' but it is just unstaging the staged step but not removing the file file3.py.

visha@LAPTOP-ID7C05LT MINGW64 ~/OneDrive/Desktop/checks (master)

$ code file3.py

MINGW64 ~/OneDrive/Desktop/checks (master)

$ git status On branch master Untracked files: (use "git add ..." to include in what will be committed) file3.py nothing added to commit but untracked files present (use "git add" to track)

MINGW64 ~/OneDrive/Desktop/checks (master)

$ git add file3.py

MINGW64 ~/OneDrive/Desktop/checks (master)

$ git status On branch master Changes to be committed: (use "git restore --staged ..." to unstage) new file: file3.py

MINGW64 ~/OneDrive/Desktop/checks (master)

$ git reset HEAD file3.py

MINGW64 ~/OneDrive/Desktop/checks (master)

$ git status On branch master Untracked files: (use "git add ..." to include in what will be committed) file3.py nothing added to commit but untracked files present (use "git add" to track)

Why is it not removing file3.py ?

2

There are 2 best solutions below

4
On BEST ANSWER

If file3.py is untracked, then there's nothing git can do to remove it. You should instead just remove it locally: rm file3.py

0
On

actually git clean removes untracked files; I find it pretty useful at times