git-tips / tips

Most commonly used git tips and tricks.
http://git.io/git-tips
MIT License
21.39k stars 1.7k forks source link

Question about how to apply a commit to different version #157

Closed imdoge closed 6 years ago

imdoge commented 6 years ago

I have several independent versions, just like ubuntu 14.x, 15.x, 16.x, so that this versions will not be merge. if I have a commit or hotfix that wants to apply to different versions, how to do with git is the best practice? such as git cherry-pick git archive git submodule? which can deal with this? thanks!

erikmd commented 6 years ago

I don't know if this repo's owners think this is the best place to ask such questions? (unlike SO maybe);
anyway here is a feedback on your question:

Assuming the various versions you maintain have each a dedicated branch, say ubuntu-14.x, ubuntu-15.x and ubuntu-16.x, you just need to commit your hotfix in one branch (say, the most important one), and port/backport the commit in the other branches using git cherry-pick. Namely:

git checkout ubuntu-16.x
...editing...
git add files... && git commit -m "Fix something..."
git rev-parse HEAD # to get the commit ID, say 1234567...

git checkout ubuntu-15.x && git cherry-pick 1234567 # which might raise conflicts
git checkout ubuntu-14.x && git cherry-pick 1234567
git push origin ubuntu-16.x ubuntu-15.x ubuntu-14.x

In contrast, the other commands you cite (git archive, git submodule) are a bit off-topic for your use case.

imdoge commented 6 years ago

thanks...