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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With