Git: fusionar un compromiso en una rama diferente
Frecuentes
Visto 3,293 equipos
2
So I have 3 branches;
develop
- my continued development branchversion_1
- a release branchversion_2
- a release branch
I had to do a hotfix on version_2
to reship that version, it was a 2 line change in 2 files, very small.
I wanted to apply that fix to version_1
e develop
.
So I;
git checkout version_1
git merge <commit checksum>
I thought a commit only contains the changes, so would only apply those. But the merge conflicts because it tries to update all the changes between the two branches.
Is there a way to merge/move/apply ONLY the changes in a small commit to other branches?
I could just manually re-implement the hotfix on those branches, but this seems a lot of hard work, especially as more hotfixes may need to re applied and rolled out to all other branches.
Cheers, Will
2 Respuestas
3
Merging only one or a few commits mean using git cherry-pick
First cancel the merge you just did: see "¿Deshacer una fusión de Git?".
Entonces:
git checkout version_1
git cherry-pick <commit checksum>
That can apply to multiple commits or a range of commits: see "Cómo seleccionar una variedad de confirmaciones y fusionarlas en otra rama".
contestado el 23 de mayo de 17 a las 12:05
2
Tu necesitas cherry-pick
esos compromisos.
Switch to the branch where you want to add the commits:
git checkout develop
Entonces, cherry-pick
the commit. First do a git reflog
y obtener el SHA-1
of the commit of the hotfix.
Then, while you are on the branch develop
, cherry-pick
it
git cherry-pick <commit SHA obtained above>
Perform similar actions on the other branch version_1
.
contestado el 28 de mayo de 14 a las 11:05
Nota mental: Y esa fue mi Respuesta 10000 on Stack Overflow (in 68 months), less than 6 months after the Respuesta 9000. Antes de que Respuesta 8000, Respuesta 7000, Respuesta 6000, Respuesta 5000, Respuesta 4000, Respuesta 3000, Respuesta 2000. - VonC