开发者

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

开发者 https://www.devze.com 2023-03-02 12:11 出处:网络
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:

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 ste开发者_JAVA技巧p #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!!!


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消