8

There has been some question on reverting back to a commit in git but I wanted to make sure. This SO page is one that helps the most: How to revert Git repository to a previous commit?

I have a previous commit, say 1.0 for a customer and it is complete. I commit (not sure if I push) and then create a new branch to work on the next version. Now, for some reason, the binary for 1.0 is "corrupted" and I need to go back but also keep the current modifications.

git log reveals this:

commit be01d2a99ec35bbfcdbca47d5570acef8c69b275
Author: Yko <xxxxxxxxx@gmail.com>
Date:   Mon Apr 25 10:25:35 2011 -0400

So, the steps I need to take is this?

1. git add .
2. git commit "good stopping point for v1.1"
3. git checkout be01...

I am assuming step #3 modifies all the source code? This is an XCode project (iPhone app) so I just have to reload the project file, build, and have the new binary .app?

Then, goes back to the latest version 1.1 with

git checkout "latest commit #"?

Thanks,

I'm new and don't want to lose any work. Appreciate the help!!!

EDIT: Based on a few answers, I want to clarify. 1. I do not want to merge any branches. I want to go back to version 1.0 and rebuild the source to create a new binary then hop back to where I was. Suppose verision 1.0 have apples to be $1.00 and version 1.10 have apples to be $1.10. I want to go back to version 1.0, rebuild the source code where apples are $1.00, give the binary to customer x. Then, hop back to version 1.10, keep working on it.

Thanks again!!!

Community
  • 1
  • 1
oky_sabeni
  • 7,672
  • 15
  • 65
  • 89
  • How does one "go back but keep the current modifications"? How is that different from just using the 1.1 version? – eykanal May 02 '11 at 15:32
  • The version 1.1 has new stuff in it. I want to go back to 1.0 build the binary and then change back to 1.1. OK. I will give an example. suppose 1.0 has the price of apples to be $1 and then 1.1 is $1.10. The 1.1 is not ready for public yet but the 1.0 version binary is corrupted... – oky_sabeni May 02 '11 at 15:38
  • What's the output when you execute 'git branch' inside your repository? – Garrett Hyde May 02 '11 at 15:46
  • When you want to go back to your 1.1 code, just execute 'git checkout '. – Garrett Hyde May 02 '11 at 15:53
  • If you're new to git, this tutorial will help you better understand how git works. http://www.eecs.harvard.edu/~cduan/technical/git/ – Garrett Hyde May 02 '11 at 16:00

2 Answers2

4

You could do it like this:

git tag 1.0
git add .
git commit -m "good stopping point for v1.1"
git tag 1.1
git checkout 1.0
.. do your build stuff/whatever
git checkout 1.1
rtn
  • 127,556
  • 20
  • 111
  • 121
0

Your steps are just fine, and you will not lose any work doing it that way. You may want to check out the git stash command to avoid step 2 if you're not really at a good stopping point.

eykanal
  • 26,437
  • 19
  • 82
  • 113