zoukankan      html  css  js  c++  java
  • git 常用命令

    一, 查看:

    git status
     # 查看有变更的文件
    
    git log 
     # 显示当前分支的版本历史
    
    git log --stat
    # 显示commit历史,以及每次commit发生变更的文件
    
    git diff
    # 显示暂存区和工作区的代码差异
    
    git blame [file]
    # 显示指定文件是什么人在什么时间修改过
    
    git show [commit]
    # 显示某次提交的元数据和内容变化

    git branch
    # 列出所有本地分支

    git branch -r 
    # 查看所有远程分支
    
    git branch -a 
    # 查看所有分支


     
     
     

    二, 增加 创建分支 并提交到远程分支:

    git branch -r 
    # 查看所有远程分支
    
    git branch -a 
    # 查看所有分支
    
    git checkout branch-name 
    # 新建一个分支但是依然停留在当前分支

    git checkout -b branch-name
    # 新建一个分支,并且切换到该分支

    git branch --track[branch-name][remote-branch-name]
    # 新建一个分支与指定的远程分支建立追踪关系

    git branch --set-upstream [branch] [remote-branch]
    # 建立追踪关系,在现有分支与指定的远程分支之间

    git merge [branch]
    # 合并指定分支到当前分支
     
     

    三, 删除:

    git branch -d [branch-name]
    # 删除分支
    
    
    git push origin --delete [branch-name]
    git branch -dr [remote/branch]
    # 删除远程分支 1
    
    git branch -r -d origin/branch-name  
    git push origin :branch-name 
    删除远程分支  2

    四, 代码回滚:

    git checkout [file]
    # 恢复暂存区的指定文件到工作区
    
    
    git checkout [commit] [file]
    # 恢复某个commit的指定文件到暂存区和工作区
    
    
    git checkout .
    # 恢复暂存区的所有文件到工作区
    
    
    git reset [file]
    # 重置暂存区的指定文件,与上一次commit保持一致,但工作区不变
    
    
    git reset --hard
    # 重置暂存区与工作区,与上一次commit保持一致
    
    
    git reset [commit]
    # 重置当前分支的指针为指定commit,同时重置暂存区,但工作区不变
    
    
    git reset --hard [commit]
    # 重置当前分支的HEAD为指定commit,同时重置暂存区和工作区,与指定
    commit一致
    
    
    git reset --keep [commit]
    # 重置当前HEAD为指定commit,但保持暂存区和工作区不变
    
    
    git revert [commit]
    # 新建一个commit,用来撤销指定commit
    # 后者的所有变化都将被前者抵消,并且应用到当前分支
    
    
    git stash
    git stash pop
    # 暂时将未提交的变化移除,稍后再移入
    
    
    
    git archive
    # 生成一个可供发布的压缩包
    
    git reset --hard version-num
    # 回滚到指定版本
    
    git revert HEAD 撤销前一次 commit
    
    git revert HEAD^ 撤销前前一次 commit
    
    git revert fa042ce57 撤销指定的版本,撤销也会作为一次提交进行保存。
  • 相关阅读:
    volatile关键字
    const关键字祥解
    extern关键字祥解
    gcc和g++使用澄清
    [APIO2014]连珠线
    点名
    四轮车
    盘子序列
    序列问题
    长途旅行
  • 原文地址:https://www.cnblogs.com/win-lin08/p/8669795.html
Copyright © 2011-2022 走看看