Reputation: 6516
I'm new in git and I'm wondering if it is possible to reset changed to unstaged file? For example.
echo 1 > file1.txt
git add file1.txt
git commit -m "file1 added to repo"
echo 2 > file1.txt
git add file1.txt
echo 3 > file1.txt
State of my repo looks like this now:
1
2
3
How to reset file to point 2 (reset changes made by command echo 3 > file2.txt
)
Upvotes: 2
Views: 1777
Reputation: 6516
Problem solved. I needed to use git checkout -- file1.txt
. I didn't saw git help (use "git checkout -- ..." to discard changes in working directory) because primarily my file wasn't yet in repo. After I added file to repo git shows mi this tip.
Upvotes: 1
Reputation: 2374
If you want to unstage file1.txt:
git reset file1.txt
If you want to unstage everything (which is the same in this case):
git reset
Upvotes: 1
Reputation: 1476
Use
git clean -n
to check what files will be deleted and then
git clean -f
to delete untracked files
Upvotes: 2
Reputation: 1850
By doing
git checkout file2.txt
will reset your changes for unstaged file
Upvotes: 1
Reputation: 13354
Per the notes that git gives you, you'd do:
git reset HEAD file1.txt
This will move file1.txt
out of tracked to untracked files.
Upvotes: 1