Ho usato git checkout -bper creare un nuovo ramo. Penso che git branchfaccia la stessa cosa. In cosa differiscono questi due comandi, se differiscono affatto?
Ho usato git checkout -bper creare un nuovo ramo. Penso che git branchfaccia la stessa cosa. In cosa differiscono questi due comandi, se differiscono affatto?
Risposte:
git checkout -b BRANCH_NAMEcrea un nuovo ramo e controlla il nuovo ramo mentre git branch BRANCH_NAMEcrea un nuovo ramo ma ti lascia sullo stesso ramo.
In altre parole, git checkout -b BRANCH_NAMEfa quanto segue per te.
git branch BRANCH_NAME # create a new branch
git checkout BRANCH_NAME # then switch to the new branch
git branch crea il ramo ma rimani nel ramo corrente che hai estratto.
git checkout -b crea un ramo e lo verifica.
Potrebbe essere considerata una forma abbreviata di:
git branch name
git checkout name
git branch: Mostra tutti i tuoi ramigit branch newbranch: Crea un nuovo ramogit checkout -b newbranch: Crea un nuovo ramo e passa immediatamente a quel ramo. È lo stesso git branch newbranchseguito da git checkout newbranch.C'è anche un'altra bandiera da menzionare, che è relativa a questi ..
git checkout -B BRANCH_NAME
Questo è un comando molto utile che ho usato di recente. Questo comando estrae il ramo specificato e reimposta il ramo in base al ramo di origine.
If -B is given, <new_branch> is created if it doesn't exist; otherwise, it is reset. This is the transactional equivalent of $ git branch -f <branch> [<start point>] $ git checkout <branch>
checkout -Bpericoloso se il ramo a cui stai passando è condiviso da altri? L'ho usato di recente e mi è sembrato di fondere automaticamente le modifiche nell'altro ramo con il ramo in cui sono passato.
git checkout -Bsì, si
Esistono forme di entrambi i comandi simili (guardando git-scm docs versione 2.11.1):
git branch <branchname> <start-point>
e
git checkout -b <new_branch> <start_point>
La seconda esecuzione del comando primo ramo e quindi aggiungendo cassa. In quella forma riferimenti espliciti al documento di git-branch:
Se si specifica -b, viene creato un nuovo ramo come se fosse stato chiamato git-branch [2] e poi estratto
Essenzialmente :
A-git branch ti consente di creare un ramo semplice e chiaro.
B -git checkout -b ti consente di creare un ramo e passare ad esso allo stesso tempo.
Quando userete quale? 1- git branch quando si desidera creare un ramo ma rimanere sul ramo corrente. 2- git checkout -b quando si desidera creare e cambiare. Se lo guardi è intuitivo creare un ramo e passare ad esso. Quindi la scelta è tua :)