-2

Now I have following structure of GIT repository:

enter image description here

Now I locate at revision #6

I want to move to revision #1

I afraid to do something because I didn't want to lost revisions 2,3,4,5,6.

Please, help me resolve this issue.

P.S.

I use tortoise git or intellij-idea for git management.

gstackoverflow
  • 31,683
  • 83
  • 267
  • 574
  • So, you're currently on the branch 'branch', and this branch's head is at rev 6, right. `git checkout master` will get you back the master, at revision 1. Then `git checkout branch` will switch back to the branch. – JB Nizet Oct 25 '14 at 08:44
  • git.exe checkout master -- terminal-company/src/main/java/com/terminal/dao/impl/TerminalDaoImpl.java: needs merge terminal-company/src/main/webapp/WEB-INF/pages/member/createCompany/addTerminal.jsp: needs merge error: you need to resolve your current index first – gstackoverflow Oct 25 '14 at 08:47
  • What is the output of `git status`. Post it in your question. – JB Nizet Oct 25 '14 at 08:59
  • @JB Nizet unfortunately I cannot answer this comment because I have already did something and it is working but I didn't understand concrete steps to reproduce it. – gstackoverflow Oct 25 '14 at 14:50

2 Answers2

0

You can checkout ant random version by using command

git checkout SHA1

Since those are commits; that means those are either committed by you. In that case you can recover them by reaching out commits by command

git reflog 
git checkout SHA1

If those are committed by some else and you have pulled them you can reset your branch (say master) as follows

git fetch 
git reset --hard master origin/master
forvaidya
  • 2,255
  • 2
  • 17
  • 24
  • so he's brand new to git and you are recommending detached head state and hard resets? That makes no sense. – Andrew C Oct 25 '14 at 13:48
  • That depends on whether or not you think the OP was asking how to go into detached head at SHA1 (it seems unlikely to me that was their goal). Also, the reflog portion is incorrect, I presume you meant `git log` – Andrew C Oct 25 '14 at 13:55
  • no I meant **git reflog** indeed. If commits are done in current git clone and not pushed yet. If commits are not done in this specific clone that means commits are actually pushed in remote server (example github) in that case solution #2 applies – forvaidya Oct 25 '14 at 14:03
  • It makes no sense that you would ever want to use reflog instead of log for listing out that history. Log returns those SHAs no matter how or when they were created. Reflog has all kinds of failure models. – Andrew C Oct 25 '14 at 14:25
-1

If you have changes and you don't want to commit them you need to stash your uncommitted work and then you can pull it back in the future.

git stash
git checkout master
[do some stuff]
git checkout [branch]
git stash apply --index

You are now back to where you were

If you have committed then you don't need to stash, just checkout master and then checkout branch once you have done anything you need on master

  • [do some stuff] - what the stuff? – gstackoverflow Oct 25 '14 at 08:49
  • whatever changes you want to make with the master - you can make changes on master and then go back to your branch. The branch will then need to be merged back into master at some point to consolidate all the changes into master – velvetytoast Oct 25 '14 at 09:01
  • Don't know why you're giving -1 for this. It answers the question exactly - all you need to do is checkout master but this also protects you from losing any un-committed work – velvetytoast Oct 25 '14 at 19:19