zoukankan      html  css  js  c++  java
  • Git Cheat Sheet——Git的常用命令和最佳做法

    一、常见命令

      1、创建

          克隆现有的存储库

    $ git clone ssh://user@domain.com/repo.git
    

          创建新的本地存储库

    $ git init 
    

      2、本地变化

      更改工作目录中的文件

    $ git status 
    

      对跟踪文件的更改

    $ git diff 
    

      将所有当前更改添加到下一次提交

    $ git add .  
    

      将< file >中的一些更改添加到下一次提交

    $ git add -p <file> 
    

      提交跟踪文件中的所有本地更改

    $ git commit -a 
    

      提交先前阶段的更改

    $ git commit 
    

      更改最后提交
      不要修改发布的提交!

    $ git commit --amend  
    

      3、提交历史

      显示所有提交,从最新开始

    $ git log 
    

      显示特定文件随时间的变化

    $ git log -p <file>  
    

      谁在< file >中更改了内容和时间?

    $ git blame <file> 
    

      4、分支和标签

      列出所有现有分支

    $ git branch -av  
    

      切换分支

    $ git checkout <branch>  
    

      根据当前的头部创建一个新分支

    $ git branch <new-branch> 
    

      基于远程分支创建新的跟踪分支

    $ git checkout --track <remote/bran- ch>
    

      删除本地分支

    $ git branch -d <branch> 
    

      提交标签

    $ git tag <tag-name> 
    

      5、更新和发布

      列出所有当前配置的远程主机

    $ git remote -v   
    

      显示有关远程

    $ git remote show <remote>   
    

      添加名为< Remote >的新远程存储库

    $ git remote add <shortname> <url> 
    

      从< Remote >下载所有更改,但不要集成到Head中

    $ git fetch <remote>  
    

      下载更改并直接合并/集成到头中

    $ git pull <remote> <branch>   
    

      在远程上发布本地更改

    $ git push <remote> <branch>
    

      删除远程上的分支

    $ git branch -dr <remote/branch> 
    

      发布标签

    $ git push --tags
    

      6、合并和重基

      将<分支>合并到当前的头部

    $ git merge <branch> 
    

      将当前的头重新定位到<分支>
      不要重新发布已发布的提交!

    $ git rebase <branch>   
    

      中止重基

    $ git rebase --abort 
    

      解决冲突后继续重基

    $ git rebase --continue   
    

      使用配置的合并工具解决冲突

    $ git mergetool  
    

      使用编辑器手动解决冲突,并(在解决后)将文件标记为“已解决”。

    $ git add <resolved-file>    
    $ git rm <resolved-file> 
    

      7、撤销

      放弃工作目录中的所有本地更改。

    $ git reset --hard HEAD  
    

      放弃特定文件中的本地更改。

    $ git checkout HEAD <file> 
    

      还原一个提交(通过产生一个新的具有相反更改的提交)

    $ git revert <commit>  
    

      将头指针重置为上一次提交
           …并放弃自那以后的所有变化 

    $ git reset --hard <commit>    
    

      …并将所有更改保留为未分阶段的更改。

    $ git reset <commit>   
    

      …并保存未提交的本地更改。

    $ git reset --keep <commit>   
    

      

  • 相关阅读:
    ~是什么意思 在C语言中,~0代表什么
    window中普通用户无法登录远程桌面
    服务器22端口被封锁的问题解决
    让hive的表注释和字段注释支持中文
    MySQL Workbench在archlinux中出现 Could not store password: The name org.freedesktop.secrets was not provided by any .service files的错误
    记使用talend从oracle抽取数据时,数字变为0的问题
    记mysql中时间相关的一个奇怪问题
    使用dbeaver查mysql的表会导致锁表的问题
    oracle中实现某个用户truncate 其它用户下的表
    Oracle中找出用户的上次登录时间
  • 原文地址:https://www.cnblogs.com/windok/p/12843702.html
Copyright © 2011-2022 走看看