J. Sm
J. Sm

Reputation: 27

Undo changes in git not staged (master branch)

I've got a master branch and someone did a few changes in it which I don't want. Is it possible to undo the changes without committing?

Current status:

git status
On branch master
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:   bazinga.php
        modified:   bazinga2.php

no changes added to commit (use "git add" and/or "git commit -a")

So basically revert to the old bazinga/bazinga2 files.

Upvotes: 1

Views: 108

Answers (2)

Ayan
Ayan

Reputation: 2380

Setting your branch to exactly match the remote branch can be done

git fetch origin
git reset --hard origin/master

Or

git checkout .

Reference: Reset local repository branch to be just like remote repository HEAD

Upvotes: 0

Ben Lee
Ben Lee

Reputation: 102

One answer hides in the git status information

(use "git checkout -- ..." to discard changes in working directory)

Try to use the command below.

git checkout bazinga.php
git checkout bazinga2.php

Upvotes: 2

Related Questions