pepuch
pepuch

Reputation: 6516

Git reset changes from unstaged file

I'm new in git and I'm wondering if it is possible to reset changed to unstaged file? For example.

  1. echo 1 > file1.txt
  2. git add file1.txt
  3. git commit -m "file1 added to repo"
  4. echo 2 > file1.txt
  5. git add file1.txt
  6. echo 3 > file1.txt

State of my repo looks like this now:

  1. In repo I've got file with content 1
  2. In stage I've got file with content 2
  3. In working dir I've got file with content 3

How to reset file to point 2 (reset changes made by command echo 3 > file2.txt)

Upvotes: 2

Views: 1777

Answers (5)

pepuch
pepuch

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

elmart
elmart

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

igoris
igoris

Reputation: 1476

Use

git clean -n

to check what files will be deleted and then

git clean -f

to delete untracked files

Upvotes: 2

JoeC
JoeC

Reputation: 1850

By doing

git checkout file2.txt

will reset your changes for unstaged file

Upvotes: 1

CDub
CDub

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

Related Questions