Question

I'm using TortoiseGit, and I want to go back to the end of a branch last committed three days ago. I've hard reset a couple of times but since I'm unfamiliar with git I risk doing something foolish and would appreciate help.

Looking at the image here:

enter image description here

'master' is currently set at the version made at 17:40:56 on 10 Jan. This is where I'd like the latest version to be both locally and remotely. (Some text redacted in this image).

However, I see that origin/HEAD and origin/master are at the version made at 11:04:01 on 13 Jan (today).

So for clarity, I want to revert to the end of the green branch, and make that version the master version. What must I do to get there?

Please say if I need to provide more information...

Was it helpful?

Solution

You should be able to right click on that commit referenced by master, select push, and select the "force" option in order to push --force your master onto the remote.
("Force Overwrite Existing Branch (May discard changes)")

Make sure to communicate that to other using that same remote repo, because you would be changing an history that others might already have pulled from.

http://joelabrahamsson.com/PageFiles/215/1664_1998.jpg

OTHER TIPS

I have partial answer to your question. I don't know tortoisegit so what are the black and red lines in the graph? I imagine the green is master branch. Is this image for local repo? What is your current branch name?

Using git on commandline/terminal window you can do following.

You can move HEAD to any commit. For brevity, lets say the SHA of Jan 10th 17:40:56 commit is c. If this is your commit history/log.

a----b----c----d----e <-- master branch 
                    ^
                    HEAD

So, doing git checkout c should set the HEAD where you want leaving the later commits in place.

a----b----c----d----e <-- master branch 
          ^
          HEAD

This is called detached state. If you do git branch, it says so. You can continue to do new commits from this point, but since they are not referenced by any branch, git can garbage collect them.

Alternately, if you want to delete commits d and e and move HEAD to c, do git reset --hard c. If you want to leave d and e changes in there but move HEAD and master branch to c, do git reset --soft c. You'll see the d and e as changes to be committed in git status.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top