On branch master Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: dir2/f2.txt
no changes added to commit (use "git add" and/or "git commit -a")
而使用上述 git checkout dev -- dir2/f2.txt 命令之后,dir2/f2.txt 是已暂存、待提交的状态。
1 2 3 4
On branch master Changes to be committed: (use "git restore --staged <file>..." to unstage) modified: dir2/f2.txt
Initialized empty Git repository in ~/project/.git/ No branches exist yet. Base branches must be created now. Branch name for production releases: [main] Branch name for "next release" development: [develop]
How to name your supporting branch prefixes? Feature branches? [feature/] Release branches? [release/] Hotfix branches? [hotfix/] Support branches? [support/] Version tag prefix? []
$ git branch * develop main
功能分支 - feature branch
每个新功能都应该驻留在自己的分支(branch)中,可以将其推送到中央存储库以进行备份/协作。但是,功能分支不是从 main 分支出来,而是把 develop 作为父分支。当一个特性完成时,它会被合并回 develop。功能分支不应该直接与 main 发生交互(例如:合并到main ).
git checkout main git checkout -b develop git checkout -b feature_branch # work happens on feature branch git checkout develop git merge feature_branch git checkout main git merge develop git branch -d feature_branch
除了 feature 和 release 流程,一个 hotfix 例子如下:
1 2 3 4 5 6 7
git checkout main git checkout -b hotfix_branch # work is done commits are added to the hotfix_branch git checkout develop git merge hotfix_branch git checkout main git merge hotfix_branch