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

    git学习地址: http://backlogtool.com/git-guide/cn/intro/intro1_1.html    http://sfsheng0322.github.io/2016/02/29/git-branch.html
     
    代码回滚参考地址    http://www.cnblogs.com/qualitysong/archive/2012/11/27/2791486.html
    可以在 .bash_profile中添加别名命令或者别名脚本
     
    配置信息:
    1.git log --decorate --graph --oneline -10   提交成功后用decorate变为一行,

    2.git prelog 可以查看之前所有本地的commit信息 ,git cherry-pick 提交号  可以取回来

     

    3..git/logs/refs/heads  里面含有所有的分支,和各自本地的commit记录,第二列为commit号,可以通过git cherry-pick 提交号  可以取回来   

     

    4. git config --global alias.st status        git config --global alias.co checkout   git config --global alias.ci commit  

     

       git config --global alias.br branch

     
    5. git config --global color.ui true  
    6. git config -l 可以查看所有的配置信息    git config user.name 查看用户名  git config user.email 查看电子邮箱 
       git commit -m "comment" 避免打开commit模板
    7. git commit -am "messages "  一条命令,包含add和commit 
    操作信息:
    1.  删除远程分支:
    $ git push origin --delete <branchName>
    

          删除远程tag:

    git push origin --delete tag <tagname>
        删除本地tag
        git tag -d <tagname>
     
        创建tag
        git tag -a <tagname> -m "create tag commit message"
     
        把本地建立好tag推送到远程
        git push origin <tagname>
     
        创建本地分之
        git branch <branchName>
     
        将本地分之推送到远程
        git push origin <branchName>
     
        把本地某个分之代码 提交 到远程库中某个分之
        git push origin <localBranchName>:<RemoteBranchName>
     
        把远程库中某个分之代码 拉取 到本地某个分之
        git pull origin <RemoteBranchName>    // 将远程RemoteBranchName分之拉取到本地当前分之上面
     
        将其它人仓库的developer分之拉取到本地当前分之上面
        git pull https://github/wutianlong/demo developer   
     
       把提交从index中拿回来到本地,就是在git add 之后再拿回来
       git reset operationfile
     
       本地已经commit了修改,并且push 到远程仓库了,此时意识到没有修改完全,但是又不想在远程仓库的commit message中再追加一条,如下操作:
       本地开始二次修改   |      git add .       |       git commit  --amend  -m “second commit mesage ,will replace first commit message”     
        git push origin <localBranchName>:<RemoteBranchName>   --force  
     
       撤销某次已经提交到远程仓库的提交, 这样会撤销之前的commit,作为一个新的commit提交,commit message中会继续追加一条
       git revert  将要撤销提交的SHA提交号
       git push origin <localBranchName>:<RemoteBranchName>      
     
       根据之前提交的commit号来拉取分之
       git   checkout   SHA-1
       git   branch    <newLocalBranchName>        
     
       只是查看某个人的提交信息       git   log   --pretty=oneline    --author="wutianlong"
     
     如果 忽略 已经在远程库中已经追踪的文件    (if you are trying to ignore changes to a file that's already tracked in the repository (e.g. a dev.properties file that you would need to change for your                                                                              local environment but you would never want  to check in these changes) than what you want to do is: )
     git update-index --assume-unchanged  <file>
     
      如果 开始 追踪远程库中忽略的文件
      git update-index --no-assume-unchanged  <file>
     
     
     
    异常信息处理:
    1. 出现 The remote end hung up unexpectedly 异常,做如下处理:
      git config --global http.postBuffer 524288000
     
    合并分之:
    从developer 合并到master 时候,默认会有很多条commit message 在master 的log里面,可用--squash 来只留一条
    git checkout master
    git merge --squash developer
    git commit -m “将dev”
     

    冲突解决方法 :
    git pull  时候出现共同修改的文件 pull不下来 
    应该本地先提交 :1.git add   2.git commit  
    再进行git pull 重新更新下来,如果更新下来则说明没有冲突,因为共同修改的不在同一行,会自动merget成功。如果没有pull下来,则说明有共同修改同一行
     
    git pull== git fetch + git merge 
     
     
    忽略文件无法进行忽略处理:
    1.git rm -r project/bin  删除bin整个文件夹东西
    2. git commit -m  "comment 信息"  只会提交HEAD最新一次commit代码   如果是-am   则是将本地全部的修改都提交上了,包括没有在index中的,非常危险
    3. .gitignore文件 ,如果要忽略的内容已经在远程库repositories中了,则无法进行忽略,需要在创建库时删除掉或者git rm -r project/folder才可以
     
    pull的流程:
    Git中从远程的分支获取最新的版本到本地有这样2个命令:
     
    1.  git fetch:相当于是从远程获取最新版本到本地,不会自动merge
     
            git fetch origin master                        // 获取远程master分之到本地临时origin/master分之
            git log -p master..origin/master         // 比较本地master分之和 临时origin/master分之 区别
            git merge origin/master                     // 将临时origin/master分之合并到本地master分之上

       上述过程其实可以用以下更清晰的方式来进行:
       
            git fetch origin master:tmp                // 获取远程master分之到本地临时tmp分之
            git diff tmp                                         // 比较本地master分之和 tmp分之 区别
            git merge tmp                                    // 将tmp分之合并到本地master分之上


    2. git pull:相当于是从远程master分之上获取最新版本并merge到本地当前分之
       
           git pull origin master                          //上述命令其实相当于git fetch 和 git merge

        在实际使用中,git fetch更安全一些, 因为在merge前,我们可以查看更新情况,然后再决定是否合并
     

    假设要合并最后的2个提交

    1. git rebase –i HEAD~2

    2. 将第二个pick修改为squash或者s,然后输入":wq”退出。

    3. 这时git会自动第二个提交合并到第一个中去。并提示输入新的message(就是我们常说的comments)

    4. 编辑输入新的message,然后输入":wq"退出

    5. 此时本地的(HEAD中)最后两次提交已经被合并为一个。git log可以查看。

    6. 如果需要提交到远端,运行git push  origin master --force即可。

    ===========================================

    虽然xcode内置强大的git 工具。但是当你工程文件冲突时,就不得不在xcode外合并。

    1
    2
    3
    4
    5
    6
    git config --global merge.tool diffmerge
    git config --global mergetool.diffmerge.cmd "/Applications/DiffMerge.app/Contents/MacOS/diffmerge --merge --result=$MERGED $LOCAL $BASE $REMOTE"
    git config --global mergetool.keepBackup false
     
    git config --global diff.tool diffmerge
    git config --global difftool.diffmerge.cmd "/Applications/DiffMerge.app/Contents/MacOS/diffmerge $LOCAL $REMOTE"

     安装diffmerge

     在git仓库目录下运行 git mergetool 就可以了 

    master 分之上之行merge命令,merge developer时,如果出现冲突

    1.想要全部保留developer 分之  则  git checkout --theirs  file-name     

    2. 想要全部保留master分之  则  git checkout --ours  file-name     


  • 相关阅读:
    ECharts之柱状图 饼状图 折线图
    Vue自定义指令(directive)
    HDU 1231 最大连续子序列
    POJ 2533 Longest Ordered Subsequence
    HDU 1163 Eddy's digital Roots
    HDU 2317 Nasty Hacks
    HDU 2571 命运
    HDU 4224 Enumeration?
    HDU 1257 最少拦截系统
    HDU 2740 Root of the Problem
  • 原文地址:https://www.cnblogs.com/wutianlong/p/5330081.html
Copyright © 2011-2022 走看看