Reputation: 4770
I am trying to do something I think is basic.
I have a remote repository(origin) and a local(master) repository.
I have done:
COMMIT/PUSH 2018-12-10 COMMIT/PUSH 2018-12-09 COMMIT/PUSH 2018-12-07 COMMIT/PUSH 2018-12-06 COMMIT/PUSH 2018-12-05
All I want to do now, is make my local/and remote branches be at the state they were at on: 2018-12-07
I have googled and searched all around here, but there is so many answers using all kinds of terms that I have no idea what is happening. I just want to "UNDO" what was done. How can I do this? The id of my commit that I want to go back to is: e18782b if that makes a difference.
I have been able to do "CHECKOUT" on this 2018-12-07 version, so my local files are exactly as I want, but then it won't let me push it to remote, it keeps saying to run pull first, after which I'm right back to where I started....
Upvotes: 0
Views: 35
Reputation: 83527
First of all, let's clarify some terminology and names:
origin
- the remote repositorylocal
- the local repostiorymaster
- the default name for the main branch of a repositoryorigin/master
- a local copy of the master
branch from the origin
repoHere master
isn't special as far as git itself is concerned. However, it should be treated specially by your processes and kept as a stable version of your project. Other branches should be created for continued work and only merged to master
when work is complete.
To answer your question, you can checkout the branch you want to reset, reset it, then push it to origin
:
git checkout master
git reset --hard e18782b
git push -f
You can replace master
with the appropriate branch name. Note that this will discard all commits past e18782b
, so be sure that you really don't want those changes. Also, it will throw away all local changes that have not been committed. The commits that you throw away can be recovered with a little work, but the uncommitted local changes cannot be recovered with git.
Upvotes: 1
Reputation: 30212
This will, for all practical purposes, get rid of what you did post e18782b, assuming you are already working on the local branch you want to hack:
git reset --hard e18782b
git push origin -f <name-of-branch>
Make sure there are no pending changes laying around your working tree because git reset --hard will get rid of them.
Upvotes: 1