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

    工作中使用到git管理工具,下面是自己经常使用的命令:

    首先新建本地仓库:

    mkdir  zrh

    cd   zrh

    git  clone git@192.168.1.xx:/home/git/repositories/rk .

    (该路径通过git remote -v 产生)

    1、git branch   查看本地分支

    2、git branch -a  查看本地和远程的所有分支

    3、git log 查看历史提交信息

    4、git checkout xxx 切换到xxx分支

    5、git checkout -b xxx 在当前分支上新建一个xxx分支,并直接切换到该新建分支

    6、git pull origin xxx 从远程仓库同步xxx分支代码到本地仓库

    7、git push origin xxx 将本地仓库的内容提交到远程仓库

    8、git add xxx1  xxx2  将xxx1和xxx2增加到本地仓库缓存中

    9、git commit xxx1 xxx2 -m "描述提交信息" 将本次修改的所有内容提交到本地仓库branch仓库

    10、git clean -df 清空本地仓库,但不清空缓存区

    11、git checkout -f 清空当前所有修改内容和缓存区

    12、git show  xxx  显示修改的内容(xxx为commit号)

    13、git branch -D xxx  删除xxx分区

    14、git reset --hard xxx 本地回退 (xxx为commit号)

    15、git remote prune origin 删除远程已经删除的分支

    16、git push origin :xxx 删除远程仓库xxx分支

     一、上传修改的代码需要的步骤:

    1、git pull origin xxx 同步服务器代码到最新

    2、git add xxx 添加xxx到本地仓库缓存区

    3、git commit xxx -m “相关提交描述”

    4、git push origin xxx  推上远程仓库

    二、推错修改到远程服务器的解决方法:

    1、git reset xxx --hard 先本地回退

    2、git push xxx --force 强制推上远程仓库

    3、git push origin xxx  -f  强推上服务器

    三、给git添加显示颜色:

    git config --global color.status auto

    git config --global color.diff auto

    git config --global color.branch auto

    git config --global color.interactive auto

    四、git cherry-pick发生冲突的解决办法:

    例如:

    Automatic cherry-pick failed.  After resolving the conflicts,
    mark the corrected paths with 'git add <paths>' or 'git rm <paths>'
    and commit the result with:

            git commit -c 15a2b6c61927e5aed6718de89ad9dafba939a90b

     此时我们手动修改:

    1、git status  查看那些文件出现冲突

    both modified: app/models/user.rb

    2、vi app/models/user.rb 手动修改

    3、git add app/models/user.rb

    4、git commit -c <新的commit号>

    五、git clean  删除一些没有git clean 的文件

    git clean -n 显示将要删除的文件和目录

    git clean -f 删除文件

    git clean -df 删除文件和目录

    六、git apply补丁

    假设在/home/zrh/test/xxx.c

    git  diff > xxx.patch  则产生的xxx.patch补丁里的路径信息是/home/zrh/test

    如果在/home下使用则执行:patch -p1 < xxx.patch 。

    使用git diff 产生的patch文件,执行patch命令时,指定-p1,在什么位置制作的patch,就在什么位置执行patch

    或使用git apply xxx.patch

  • 相关阅读:
    JSP学习-10-EL表达式
    深入浅出Mybatis(一)
    第10章—开启事务
    第09章—使用Lombok插件
    第08章—整合Spring Data JPA
    第06章—热部署
    第05章—Swagger2打造在线接口文档
    第03章—打造RESTful风格API
    第04章—整合Mybatis
    第01章—快速构建
  • 原文地址:https://www.cnblogs.com/zhou2011/p/3273257.html
Copyright © 2011-2022 走看看