Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Revert back to a specific commit in git, build, then revert to the latest changes

Tags:

git

xcode

iphone

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 <[email protected]>
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!!!

like image 898
okysabeni Avatar asked May 02 '11 15:05

okysabeni


People also ask

Can I go back to a specific commit in git?

An administrator can roll back the code repository to a previous commit -- that point-in-time copy -- in several ways, depending on the end goal. One approach is the git reset command. Before using this command, you must understand what git reset does.


1 Answers

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
like image 171
ralphtheninja Avatar answered Oct 12 '22 04:10

ralphtheninja