0
点赞
收藏
分享

微信扫一扫

高级软件工程 git rebase操作

我阿霆哥 2022-03-30 阅读 55
git微软

第一次作业

实时查看git提交生成树

	1. 在线学习网站,windows,linux均可,可用于自己测试。 https://learngitbranching.js.org/?locale=zh_CN
	2. 如用linux操作系统,可使用gitk --all命令查看提交历史。如没有gitk也可使用命令sudo apt-get install gitk则需提前安装。 
	3. 如用windows系统,自行安装git bash,可直接使用命令gitk --all查看提交记录。

实现上图所示的提交生成树

  • 创建一个新的文件夹

    mkdir git_lab
    cd git_lab
    
  • git clone远程仓库,选择自己的仓库克隆一个空项目

    git clone https://gitee.com/fragile_xia/empty_project.git
    
  • 进行第一次提交作为起点

    git add .
    git commit -m "c1"	
    
  • 创建一个新的分支

    git checkout -b branch1
    
  • 修改文件

    cd empty_project
    vim README.txt
    修改文件后保存
    
  • 提交一次作为新分支的起点

    git add .
    git commit -m "c2"
    
  • 修改文件并提交(到达A结点)

    git add .
    git commit -m "c3"
    
  • 修改文件并提交 (到达B结点)

    git add .
    git commit -m "c4"
    
  • 切回主分支

    git checkout master
    
  • 修改文件并提交

    git add .
    git commit -m "c5”
    
  • 修改文件并提交

    git add .
    git commit -m "c6"
    
    
  • 在本地或云端修改文件后,与云端分支合并

    git pull origin master
    
  • 切换回branch1

    git checkout branch1
    
  • 回退两个版本

    git rebase -i HEAD^^
    
  • 提交一次作为新分支的终点

    git commit -m "c7"
    
  • 回到主分支并且merge(branch1)分支

    git checkout master
    git merge branch1
    
  • 传到云端

    git push -u origin master
    

测试结果:(其中C2, C3结点的记录不会保存)

举报

相关推荐

0 条评论