1

I am new to Git. My question is simple but I looked into this SO LINK I could find the right answer.

Step 1. Suppose I have a project with two files in it. A.txt and B.txt. I made some changes to file and eventually I pushed it to the repo.(all good till now)

Step 2. Now I made some more changes in it. Suppose I added one line in both A.txt and B.txt.

Step 3. so now I went to cmd and did "Git Status". I saw both the file name in "Red Colour".

Step 4. Then I realized that I DO NOT want these files to go to my master repo. I mean I do not want these changes at all even in my local repo.

Step 5. Also, I have forgotten which line I have added to both A.txt and B.txt since I last successful push.

Step 6. So when I do git status "I see both the files in red colour" because of one one line changes they are carrying with them. How can I revert those changes from my local repo such that when I do git status. I should not see anything at all. I should see message as "it's in sync with remote repo".

Reiterating Myself. I want a git command which will revert changes made in my local repo in such a way that after running git command when I switch back to my project I should see message as "Some external source is trying to modify file a.txt and b.txt" And If I say yes to that prompt the one one line change that I made should be gone from my local repo as if it was never there.

P.S: Kindly note that I am not at all taking about "git add or commit or push".

Community
  • 1
  • 1
Unbreakable
  • 7,776
  • 24
  • 90
  • 171
  • I understand your edit, but git checkout is enough: you seem to describe local modifications, and they will be gone after the git checkout I mention – VonC Mar 26 '17 at 11:55
  • Thank you for understanding my question and answering it flawlessly. :) – Unbreakable Mar 26 '17 at 11:57
  • tortoisegit also helps you..we can have help from UI instead of command line – murali selenium Mar 26 '17 at 14:51
  • Possible duplicate of [How do I discard unstaged changes in Git?](http://stackoverflow.com/questions/52704/how-do-i-discard-unstaged-changes-in-git) – 1615903 Mar 27 '17 at 07:16

1 Answers1

2

"red color" means "modified, not yet added to the index" (or they would be green).

To get back their original content since last commit, simply do a git checkout -- afile:

git checkout -- A.txt
git checkout -- B.txt

That will take care of step 6. No add, commit or push involved, just the removal of pending local modifications.
Note sure about step 7 though: git stash might help, if you want to save those local modifications (which were never added, committed not pushed)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Step 7 was not a step. I was just reiterating myself. :) . Because I did want a fancy answer. I wanted a to the point answer. I want to thank you so much for providing such a simple answer. It worked as expected. – Unbreakable Mar 26 '17 at 11:56
  • 1
    OK. The git checkout command restore what was in the index before modification in the working tree. It restores the files from a branch or tree-ish, or it restores a single file. – VonC Mar 26 '17 at 12:00