Estoy escribiendo algunos guiones para mi flujo de trabajo de Git.
Necesito restablecer otra twig (existente) a la actual, sin pago.
Antes de:
CurrentBranch: commit A OtherBranch: commit B
Después:
CurrentBranch: commit A OtherBranch: commit A
Equivalente de
$ git checkout otherbranch $ git reset --soft currentbranch $ git checkout currentbranch
(Nota: suave: no quiero afectar el tree de trabajo).
es posible?
Los flujos de trabajo que describes no son equivalentes: cuando realizas un reset --hard
, pierdes todos los cambios en el tree de trabajo (es posible que quieras reset --soft
).
Lo que necesitas es
git update-ref refs/heads/OtherBranch refs/heads/CurrentBranch
Establezca otherbranch
para que apunte a la misma confirmación que currentbranch
ejecutando
git branch -f otherbranch currentbranch
La opción -f
(force) le dice a git branch
sí, realmente quiero sobrescribir cualquier reference existente de otra otherbranch
con la nueva .
De la documentation :
-F
–fuerzaRestablecer a si ya existe. Sin -f git branch se niega a cambiar una twig existente.
Puedes sincronizar con este command tus twigs en cualquier momento
$ git push . CurrentBranch:OtherBranch -f
También sin -f reemplaza este set de commands
$ git checkout OtherBranch $ git merge CurrentBranch $ git checkout CurrentBranch
Puede ser útil cuando no necesita confirmar todos sus files en CurrentBranch y por lo tanto no puede cambiar a otras twigs.