-1

Yesterday I did git pull which grab latest copy from Github repo.

I did some coding yesterday but I did not do git add .

Now I want to reset what it was from yesterday - meaning remove all the work changes from yesterday back to original (last git pull).

How to do this?

$ git status
On branch develop
Your branch is behind 'origin/develop' by 5 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   app/Http/Kernel.php
        modified:   app/Http/routes.php
        modified:   composer.json
        modified:   database/seeds/DatabaseSeeder.php

no changes added to commit (use "git add" and/or "git commit -a")
I'll-Be-Back
  • 10,530
  • 37
  • 110
  • 213
  • 1
    Possible duplicate of [How to revert uncommitted changes including files and folders?](http://stackoverflow.com/questions/5807137/how-to-revert-uncommitted-changes-including-files-and-folders) – underscore_d Aug 01 '16 at 20:02

2 Answers2

2

If you did not git add and therefore did not git commit, and just want the state to look like yesterday, a simple hard reset will fix it.

git reset --hard
merlin2011
  • 71,677
  • 44
  • 195
  • 329
  • Thanks. If the future if `git add` did happen then what the solution to this? – I'll-Be-Back Aug 01 '16 at 19:59
  • 1
    Why don't you just try it and see? What have you got to lose? Answer: only things you _want_ to lose. Trying it would be quicker than asking such basic questions, which are covered very early in any half-decent `git` tutorial. And by trying it, you'll see it makes no difference either way. – underscore_d Aug 01 '16 at 20:00
  • 1
    @I'll-Be-Back, If you added and didn't commit, the same solution would work. If you added and committed, then you need `git reset --hard origin/master`. – merlin2011 Aug 01 '16 at 20:00
0

If you haven't made any commits, another option might be to just "git stash" your changes to save them away, just in case you want to get them back again later (git stash apply or pop).

Read more at https://git-scm.com/book/en/v1/Git-Tools-Stashing

David Neiss
  • 8,161
  • 2
  • 20
  • 21