zoukankan      html  css  js  c++  java
  • git checkout 和 git checkout --merge <branch_name>使用

    一、git checkout

    //查看当前分支
    $ git branch
    master
    *t2
    testing


    //checkout会覆盖当前工作区文件和覆盖暂存区内容,所以发现分支有未提交的警告,执行git checkout master -f,强制切换后分支没提交的修改会掉失.
    $ git checkout master

    error: Your local changes to the following files would be overwritten by checkout:
    team/testing.txt
    Please commit your changes or stash them before you switch branches.
    Aborting

    二、git checkout --merge <branch_name>

    //查看当前分支
    $ git branch
    master
    t2
    *testing

    //在当前分支“testing”下对文件做一些增删改操作,如果不对增删改文件做git commit,当切换分支时这些增删改过的文件【未commit】就会掉失。所以要特别注意【切换分支前要先git commit】。

    //切换分支的时候,将当前分支修改的内容一起打包带走,同步到切换的分支下.
    //git checkout --merge 两点需要注意
    //第一,如果当前分支和切换分支间的内容不同的话,容易造成冲突。
    //第二,切换到新分支后,当前分支修改过的内容【未commit的内容】就丢失了。
    $ git checkout --merge t2

    //如果冲突手动合并 ->git add . -> git commit -m "conflict done"

    //切换分支,观察工作区文件的变化
    $ git checkout testing

  • 相关阅读:
    ubuntu18.04 复制或剪切某文件夹下的前x个文件到另一个文件夹下
    VOC2012数据集提取自己需要的类的图片和对应的xml标签
    python面试题
    vi命令使用
    缓冲(Buffer)和缓存(Cache)区别和联系
    cpu相关概念
    pycharm
    jmeter分布式部署
    LeetCode#67 Add Binary
    LeetCode#70 Climbing Stairs
  • 原文地址:https://www.cnblogs.com/chenweichu/p/5850061.html
Copyright © 2011-2022 走看看