0

enter image description here

As seen on the picture, I want to click "Checkout" but remain on the same commit. That will allow me to see all differences as if I had just made them against the most recent commit.

Another way to facilitate this would be:

  1. Check out the historical commit in a separate folder
  2. Copy all non-git files in the master branch folder

but that's a lot of work, and I don't want to admit how many times I have done it.

I am not talking about doing a reset, as in this case I want to keep the commit history. Reverting is similar, but it wouldn't let you compare the changes against the latest commit.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Eduard G
  • 443
  • 5
  • 21
  • What about using a worktree? https://opensource.com/article/21/4/git-worktree – evolutionxbox Mar 23 '23 at 16:23
  • I see that seems interesting but I am not sure it relates entirely to my case. This morning I had to undo 2 commits in our master branch, and I wanted to do that by "resetting" to a previous version while keeping my solution on the same commit so I can simply "push" after that will all the changes. I couldn't find a way to do that as Visual Studio would also want to pull incoming changes, and the only way to avoid that was to force push. I don't want to force push as it would delete the reverted commits. – Eduard G Mar 23 '23 at 16:30
  • Different worktrees can be on different commits of the same branch – Jonathan Dodds Mar 23 '23 at 18:33
  • Are you just trying to compare? In the 'Git Branch History' windows you can select any two commits and choose 'Compare Commits...' from the context menu. – Jonathan Dodds Mar 23 '23 at 18:40
  • `git checkout othercommit -- .` (executed at the root of the repo) will make your work tree and index look like the state of the repo as it was at the time of that other commit. There is also an experimental new `git restore` command that does the same thing in a less confusing way. – Raymond Chen Mar 23 '23 at 21:01
  • I must say worktrees confused me, apologies but I failed to understand what I have to do to get it working. Doing 'git checkout #commitnumber -- .' worked a charm. It pulled a historical commit with the changes, yet kept me on the latest commit so I can now simply commit all changed files as a new commit, essentially reverting the changes to a previous state with a new commit. Exactly what I needed. @RaymondChen please post it as an answer. I didn't manage to get git restore working, if you can expand more on that in your answer - great. – Eduard G Mar 28 '23 at 14:48
  • This is basically a duplicate of [How do I reset or revert a file to a specific revision?](https://stackoverflow.com/questions/215718/how-do-i-reset-or-revert-a-file-to-a-specific-revision). You just want to revert an entire directory rather than a single file. – Raymond Chen Mar 28 '23 at 17:23
  • @RaymondChen I cannot agree. That question targets a file, mine - the whole solution. From the perspective of someone who is not well versed with Git (me), that proposed duplicate will not give me the answer I need, nor will it be easy for me to find it. I recently had a question like that marked off as duplicate and deleted before any answers were given. I spent the day looking at the proposed duplicate and never managed to figure out what the answer was, so to me it was not helpful at all. – Eduard G Mar 29 '23 at 16:10
  • I still recommend worktrees since it means you can have two different commits checked out at once from the same repo. Using worktrees, the repo will be in two locations on disk. You cannot check out two commits in the same repo in the same location on disk – evolutionxbox Mar 30 '23 at 14:14
  • Thank you for bringing that up, when I have some extra time I will explore worktrees as it does sound very useful. – Eduard G Mar 31 '23 at 09:21

0 Answers0