Git Créer une branche à partir d'un commit

Stewart Nguyen 6 février 2022
Git Créer une branche à partir d'un commit

Cet article vous montrera comment créer une nouvelle branche à partir d’un commit.

Pour créer une branche à partir d’un commit SHA, utilisez la commande git branch <new_branch> <commit_sha> avec le commit comme dernier argument.

Vous pouvez également utiliser une référence symbolique au lieu de sha, par exemple, git branch <new_branch> HEAD~4.

$ git log
commit 1e087f5309ae647d16a0e1469dfd12a7cd91e22d (HEAD -> feature/changes-to-file)
Author: Cuong Nguyen
Date:   Sat Dec 18 22:01:00 2021 +0700

    Make some change to file.txt

commit ab38737fe95f4959139b995b960a0173b4dd2c7e
Author: Cuong Nguyen
Date:   Sat Dec 18 21:26:31 2021 +0700

    Hotfix #1

$ git branch branch-from-hotfix-commit ab38737fe95f4959139b995b960a0173b4dd2c7e
$ git checkout branch-from-hotfix-commit
Switched to branch 'branch-from-hotfix-commit'
$ git log
$ git log
commit ab38737fe95f4959139b995b960a0173b4dd2c7e (HEAD -> branch-from-hotfix-commit)
Author: Cuong Nguyen
Date:   Sat Dec 18 21:26:31 2021 +0700

    Hotfix #1

Pour vérifier la branche lors de sa création, utilisez git checkout -b <new_branch> <commit_sha>.

Article connexe - Git Branch

Article connexe - Git Commit