8

I have made some changes in the repository and registered a commit (on local). And then I executed this:

$ git pull origin master

And my local commit merged with the pulled one. Now I regret. I want to get the last version which is on the remote branch master and get ride of the local commit (which is merged).

I can change the working directory by this command:

// the last commit on the remove branch master
$ git checkout 84acc42 .

But if I make some changes on it and push it, I guess that previous changes still are exists and will be pushed as a commit too. Because that commit is exists.

Noted that $ git reset --hard doesn't remove anything. I executed that and still see the changes I don't want.

Any idea how can I get the last version which is on the remote repository (branch master) and remove everything else? I can do that by removing the local working directory and cloning it again from the repository. But I want to know if there is another way.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Martin AJ
  • 6,261
  • 8
  • 53
  • 111

1 Answers1

6

Fetch the origin/master.

git fetch --all

Stage all the changes. So that, No untracked files will be left behind.

git add .

Then, run reset command,

git reset origin/master --hard

This will throw away all the changes made in the branch, will be exact copy of origin/master.