• git常用命令


    1.基本知识点

    Git本地有四个工作区域:工作目录(Working Directory)、暂存区(Stage/Index)、资源库(Repository或Git Directory)、git仓库(Remote Directory)。文件在这四个区域之间的转换关系如下:在这里插入图片描述

    2.常用命令:

    第一步:git pull ssh/网址  --把代码拉到本地
        一顿操作(修改代码)............
    第二步:创建自己的分支并同步到远程
    git checkout -b 分支名
    git branch --set-upstream-to=origin/master --同步到远程仓库
    第三步:
    git add .
    git commit -m  "提交说明"
    git push origin HEAD
    
    
    
    其他一些常用的操作:
    git status  --查看状态:在那个分支上面
    git checkout master/分支  --切换到master/其他分支
    git diff:查看branch和master的差异,修改了那些内容
    git log :查看操作日志
    git fetch <remote>:访问远程仓库,从中拉取所有你还没有的数据
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    3.工作遇到的问题

    Case1: 当前分支落后于master分支

    Before preceding, you have to commit or stash all the changes you made on the branch behind commits.

    Solution:

    1. Checkout your local Master branch
    git checkout master
    
    • 1
    1. Pull from remote Master branch
    git pull origin master
    
    • 1

    Now your local Master is in sync with the remote branch. As a result of the above command, other local branches branched from the previous local Master branch are not in sync. To fix that:

    Checkout the branch that is behind your local Master branch

    git checkout BranchNameBehindCommit
    
    • 1

    Merge with the local Master branch

    git merge master  // Now your branch is in sync with the local Master branch
    
    • 1

    If this branch is on the remote repository, you have to push your changes.

    git push origin branchBehindCommit
    
    • 1

    Case2:合并多个commits

    rebase合并远程多个commits

    Case3:当前分支落后于master分支,n个 commits ahead

    结合case1+case2

    4.撤销已经push的文件

    第一步: git log --pretty=oneline   查看当前提交的日志
    第二步: git reset --soft XXX   XXX是commitID(d6cdbba417…) 回退当前工作空间的上一个版本,并且保留代码更改
    第三步: git log --pretty=oneline   再次查看当前提交的日志,确认是否成功撤销,当然,你也可以不看,基本上都会成功,保险一下,看看呗
    第四步: git push origin 远程分支 --force   强制提交当前版本号,以达到撤销版本号的目的.必须添加参数force进行强制提交,否则会提交失败,报错原因:本地项目版本号低于远端仓库版本号。(master 代表分支名称,默认是 master,或者也可以直接用git push --force)

    注意:这种强制提交的方法只有owner的时候可以用

  • 相关阅读:
    TypeScript 类型体操
    Google Earth Engine(GEE)——GEE错误结果没有变化?
    Git忽略文件.gitignore的使用
    关于技术管理的葵花宝典
    Mysql Explain 详解(荣耀典藏版)
    代码随想录刷题Day53 | 1143. 最长公共子序列 | 1035. 不相交的线 | 53. 最大子数组和
    Ubuntu系统下MySQL开启远程连接
    Dominosa/数邻(2) | C++ | BFS
    京东详情api
    洛谷刷题C语言:梦中的统计、统计天数、语句解析、爱与愁的心痛、西游记公司
  • 原文地址:https://blog.csdn.net/tian1191132442/article/details/124536944