Reputation: 97
When I run 'git checkout', I also want to delete all additional files that have been created after commit.
But I couldn't find the way. Here is the thing I tested,
I created a directory test
and made a file test/test.txt
after I commit.
Then I run git add .
and git checkout
, but the new file and directory were not deleted.
Why the new files were still exist even though I put command git checkout
as roll-back?
How can I go back to the stage completely?
Thank you for your time and reading my question.
Upvotes: 2
Views: 245
Reputation: 70135
One of the unique and useful aspects of GIT is that you have a repository and a working directory and they don't need to be in identical. As a developer you often have multiple things happening at once. A couple files ready to commit; a couple files nearly ready, a couple files there for testing, a couple files with some notes/ideas, etc. With GIT you get to decide what you want to save and when. Add and Commit what you want. Work on other stuff, Add and Commit. And so on. If during the process of getting your stuff committed you end up with stuff you don't need, then there is a trivial solution:
git status
rm <trash>
The 'git status' lets you see very clearly what you've created by decided not to add. And 'rm trash' gets rid of the stuff that is confirmed trash.
Two steps are better than one.
Upvotes: 0
Reputation: 5786
check out this thread: How do I revert all local changes in Git managed project to previous state?
As Thr4wn notes, git reset --hard
will solve your particular problem. However, as noted in the thread linked above, it will not remove untracked files: it removes your second file only because you previously ran git add .
git clean -fd
seems to be the solution that removes EVERYTHING you added after the commit (this means you will lose all those files).
Upvotes: 5
Reputation: 40599
BE CARFUL to make sure I understand your question first, but I believe that
git reset --hard
Is the command you are looking for.
What this command does, is irreversibly erases all the changes you made since the last commit.
Upvotes: 1