1

In Tortoise HgWorkbench I can right click on a saveset and select Update... which allows me to force my workspace to set its contents to match that saveset. I have to select checkbox to "Discard local changes". I'm now using TortoiseGit and also SourceTree with Git. What is the equivalent command to do an update to a previous node in a branch? Effectively I want to temporarily revert my workspace to a previous revision discarding everything that is currently in it but without losing any of my previous commits and then later return my workspace to my most recent commit.

JonN
  • 2,498
  • 5
  • 33
  • 49
  • In plain git you can do it this way http://stackoverflow.com/questions/1146973/how-do-i-revert-all-local-changes-in-git-managed-project-to-previous-state#1146981 – Sardorbek Imomaliev Nov 02 '16 at 07:13

2 Answers2

1

To revert back to a previous revision and discard subsequent local changes, open the log, right-click on the appropriate revision and choose Reset master to this.

If you want to revert back to a previous revision without affecting changes already committed, open the log, right-click on the appropriate revision and choose Switch/checkout to this.

Switch/checkout image

Similarly to TortoiseHg, the active revision is highlighted in bold: Active revision

To go back to the latest revision of master again, simply right-click on it and choose Switch/Checkout to "master":
Revert back to master

The temporary branch that was created can also be deleted by right-clicking on its log entry and choosing Delete refs/head/tmp_branch.

To open the log, right-click on a folder containing a repository (it will have a hidden subfolder called .git) and choose TortoiseGit -> Show log. The log is context-sensitive. If you then you will see the full revision history for the current branch. However it's also possible to open up the logs of sub folders or individual files to only see their revision history.

Malice
  • 3,927
  • 1
  • 36
  • 52
  • How do you get to the graph display shown in your diagrams? With TortiseHG I right click on a repository folder and select Hg Workbench but I can't find an equivalent for TortoiseGit. In SourceTree there is an right click option for "Reset current branch to this commit" would that be the same as "Switch/Checkout to this" in TortoiseGit? – JonN Nov 07 '16 at 04:05
  • I've updated my answer with a note on opening the log. For your second question, I've never used SourceTree so I can't advise on what its options might do. It sounds like it would be the same so you could try it on a test repository and see what happens. – Malice Nov 07 '16 at 15:43
  • It should be noted that the SourceTree option "Reset current branch to this commit" DOES NOT do the equivalent of an Hg Update. It does a REVERT so if you Reset three revisions back it deletes the previous three change-sets from the local repository. When I said I wanted to revert to previous version I meant in the workspace only. I did not want to destroy anything in the repository. The equivalent command to TortoiseHg Update in SourceTree Git is Checkout... – JonN Dec 10 '16 at 20:07
0

Now with a better understanding of Git branches I understand my confusion when I asked this question. So I'm sharing it for others like myself coming from Mercurial and trying to use Git for the first time.

The fundamental thing I didn't understand was what Git calls a branch is really just a pointer or reference to a specific commit node(change-set). It is not (as the name branch implies) a connected set of commits or nodes. Another basic confusion I had was that commits could exist in Git without a branch(node reference) to them. Unlike Mercurial, in Git if you move your current branch pointer back to a previous node and there is no other branch pointer referencing any of the descendant nodes then those nodes are no longer reachable and are effectively lost. When I make a commit in Mercurial the commit tree for the common use case is static. That is if I reload my workspace with a node 3 commits previous, then those three subsequent nodes are not only still reachable, they are also visible on the graph tree. But with Git there MUST be a pointer to a node or one of its descendants for it to show on the graph. That means when I move my current branch pointer to somewhere else I lose all recent commits that are descendants. Which is not at all what I intended. I just want to temporarily reload my current workspace with a previous commit for testing purposes and I don't want to change or lose any previous commits. So how do I do that with Git? The easiest way to do that is first commit any outstanding changes in my workspace and then to do a checkout of the ancestor node to a NEW branch name like RegressTest. (Like @Malice mentioned) I can then use RegressTest to load any commit in the entire tree for testing purposes. Then when I am done I can delete the RegressTest branch pointer and then checkout my current branch again. Deleting RegressTest will not lose any commits as they are already referenced by one or more other branch pointers.

The reason @Malice 's answer wasn't clear to me is I didn't understand why I needed to create a tmp_branch because I didn't understand that without a reference to a commit node Git will lose access to, or effectively delete those unreferenced nodes. Coming from Mercurial this was a foreign concept.

Added 12-27-2016 I also now understand that the unrefernced nodes are not actually deleted but are still in repository and can be accessed via commit ID and branch logs but not as easily as if they appeared on the graph.

JonN
  • 2,498
  • 5
  • 33
  • 49