zoukankan      html  css  js  c++  java
  • 3. Git分支

    3.1 分支的创建与合并

    # 创建分支

    git]# git branch br1

    # 切换到分支

    git]# git checkout br1

    Switched to branch 'br1'

    # 查看

    git]# git branch

    * br1

      master

    # git checkout -b <branch>  创建并直接切换到分支

    # 分支 br1 新添加文档 br1.txt 

    git]# git commit -m 'Add br1.txt at br1'

    git]# git checkout master

    git]# git commit -m 'Add br1.txt at master'

    # 查看项目交叉史

    git]# git log --oneline --decorate --graph --all

    * b826238 (HEAD -> master) Add br1.txt at master

    | * addf969 (br1) Add br1.txt at br1

    |/

    * a17d7c5 (tag: v1.2) Modify 3.txt

    * 018c666 (tag: v1.1) Add 2.txt

    * da183e6 Move 2.txt to 3.txt

    # 合并分支,发现冲突

    git]# git merge br1

    Auto-merging br1.txt

    CONFLICT (add/add): Merge conflict in br1.txt

    Automatic merge failed; fix conflicts and then commit the result.

    # 查看

    git]# cat br1.txt

    <<<<<<< HEAD

    br2

    =======

    br1

    >>>>>>> br1

    # 解决冲突

    git]# cat br1.txt

    br1

    git]# git add br1.txt

    git]# git commit -m 'Modify Confilict File br1.txt at Master'

    [master 72d6973] Modify Confilict File br1.txt at Master

    # 合并分支

    git]# git merge br1

    Already up to date.

    # 删除分支

    git]# git branch -d <branch>

    git]# git branch -v

      br1    addf969 Add br1.txt at br1

    * master 72d6973 Modify Confilict File br1.txt at Master

    查看未合并的分支(分支必须有新文件)

    git]# git branch --no-merged

    # 查看已合并的分支

    git]# git branch --merged

    # 查看尚未合并到master的分支有哪些

    git]# git branch --no-merged master

    3.2 远程分支

    克隆远程分支 分支命名为 luwei,克隆的文件夹重命名为 remote

    git]# git clone https://github.com/luwei0915/06_Linux -o luwei remote

    remote]# git remote

    luwei

    remote]# git ls-remote luwei

    333c9865f86a04b14db0660de2250a0d75310211        HEAD

    333c9865f86a04b14db0660de2250a0d75310211        refs/heads/master

    remote]# git remote show luwei

    * remote luwei

      Fetch URL: https://github.com/luwei0915/06_Linux

      Push  URL: https://github.com/luwei0915/06_Linux

      HEAD branch: master

      Remote branch:

        master tracked

      Local branch configured for 'git pull':

        master merges with remote master

      Local ref configured for 'git push':

        master pushes to master (up to date)

    # 添加新的远程仓库

    # git remote add <branch> URL

    # 拉取代码

    # git fetch <branch>

    # 推送

    # git push <remote> <branch>

    # 推送本地的 serverfix 分支,将其作为远程仓库的 awesomebranch 分支  推送并重命名

    # git push origin serverfix:awesomebranch

    # 查看更详细的分支信息

    # git branch -vv

    # 删除分支

    remote]# git branch -d serverfix

    # 删除远程分支

    # git push origin --delete serverfix

  • 相关阅读:
    [Daily Coding Problem 223] O(1) space in order traversal of a binary tree
    [Daily Coding Problem 224] Find smallest positive integer that is not the sum of a subset of a sorted array
    Sliding Window Algorithm Questions
    Sweep Line Algorithm Summary
    Palindrome Algorithm Questions
    Core Data Structures, Algorithms and Concepts
    [LeetCode] 1000. Minimum Cost to Merge Stones
    UVA 253 Cube painting(枚举 模拟)
    Codeforces 821C Okabe and Boxes
    Codeforce 741B Arpa's weak amphitheater and Mehrdad's valuable Hoses(并查集&分组背包)
  • 原文地址:https://www.cnblogs.com/luwei0915/p/13819261.html
Copyright © 2011-2022 走看看