当前位置: 首页 > 工具软件 > git-point > 使用案例 >

git-branch,git-checkout和repo-start三条命令的差异比较

江坚成
2023-12-01

compare Difference among git-branch, git-checkout and repo-start

1. $ repo start

used to begin a new topic branch, starting from the revision specified in the manifest.xml file. All new branches are parallel and the original branch is the same base of all new branches. Just because the revision specified in the manifest.xml file the branch out point by default, it need not to be care about which is the current branch for the $repo start command. This command can be executed in any branch,but starting point of a new branch is alwasys the revision specified in the manifest.xml file.
                
a.$repo start new-branch-1 .
b.$repo start new-branch-2 .
c.$repo start new-branch-3 .

                      O new-branch-1
                    /
                 /    
  **-branch O ---O new-branch-2 
                \
                    \
                     O new-branch-3

1)$repo start <topic-branch-name> <project1-name> [<project2-name>...]  #executed where the workspace is
   begin a new branch in the specified projects. Multiple projects are separated by spaces. ProjectX-name can be refered to the manifest file in .repo folder.
2)$repo start <topic-branch-name> --all #executed where the workspace is
    begin branch in all projects.
3)$repo start <topic-branch-name> .   #executed where the project is.
   It can also use a single period "." as a shortcut to denote the current project.

 

2. $git branch

used to list, create or delete branches. It must be executed under the folder where a project is.

1)$git branch, with no arguments, to list the existing local [topic] branches and the current branch will be highlighted with a prefix asterish(*).
2)$git branch -r |--remote, causes the remote-tracking branches to be listed.
3)$git branch -a |--all, list both remote-tracking branches and local branches.
4)$git branch <topic branch name> [<start-point>], create a new topic branch. If <start-point> is not given, then the new branch points to the HEAD of the current branch.
This command does not switch the working tree to the new branch, and the working tree still stay at the current branch.
At this time, it can use $git checkout <topic branch name> to switch the working tree to the new branch. That is,
            $git branch <topic branch name> [<start-point>]
            $git checkout <topic branch name>
The above two steps are equal to the below one step.
            $git checkout -b <topic branch name> [<start-point>]
5)$git branch -D <topic-branch-name-1> [<topic-branch-name-2> <....>], delete existing topic branches

 

3. $git checkout

checkout a branch or paths to the working tree.
1)$git checkout <branch-name> ,

   to switch among the local branches, among the remote branches, and among the local branches and remote branches. It sets the given <branch-name> branch as the current branch. This command will switch the working tree to the new created branch.

2)$git checkout -b <topic branch name> [<start-point>], to create a new local topic branch named <topic-branch-name>.
If <start-point> is not given, then the new branch points to the HEAD of the current branch, the current branch is as base of the new branch, that is, the new branch must contain the changes of the current branch.

 

Example 1: As far as the new-branch-2 branch is concerned, new-branch-2 is a new branch, and new-branch-1 is the current branch.
  a.$git checkout -b new-branch-1 . or $git checkout new-branch-1   #specify the branch out point for next new branch
  b.$git checkout -b new-branch-2 .

                                           O------------------O
                             new-branch-1        new-branch-2
                                                               

Example 2: new-branch-1 and new-branch-2 are new branches, and new-branch-1 is the current branch. new-branch-1 and new-branch-2 branches are parallel and the original branch is the same base of all new branches.
   a.$git branch -r
   b.$git checkout origin/**-branch    #specify the branch out point for next new branch
   c.git checkout -b new-branch-1
   d.$git checkout origin/**-branch   #specify the branch out point for next new branch
   c.git checkout -b new-branch-2
                                                       O new-branch-1
                                                     /
                                                   /
                                 **-branch O
                                                   \
                                                    \
                                                      O new-branch-3
                                                                     
    $git merge <topic branch name>, used to merge changes from the specified name topic branch into the current branch.

 类似资料: