zoukankan      html  css  js  c++  java
  • Git使用笔记2

    工作必备:

    【更新master】
    git checkout master
    git pull
    git checkout zyb/FirstCommit
    git merge master

    //git rebase master --> 更新 zyb/FirstCommit 分支到 master 的最新版本

    【多次 commit,日志太多,处理方法:】
    git log --graph [git log 某次提交号(适用于很多次commit的情况)]
    git reset **[创建此branch前的编号]
    git log [创建此branch到最后一次commit间的log会被删除]
    git add . [撤销:git reset HEAD <file>...]
    git commit -m "commentment"
    git push -f origin zyb/FirstCommit 【一定是 push 到自己的branch,-f 是因为log不一致】

    【创建并提交分支】
    git status
    git pull
    git checkout -b zyb/FirstCommit
    git branch -b zyb/FirstCommit
    git checkout zyb/FirstCommit
    git diff --color
    git add . [或*/*/*.sh]
    git commit -m "commentment"
    git push origin zyb/FirstCommit

    【git remote add origin 网址】
    添加远程主机,origin也是命名的,可能是git最初的建议名

    【分支】
    删除本地分支
    git branch -d the_local_branch #### If you are sure you want to delete it, run 'git branch -D zyb/modifyApiServiceDevconf'.
    git branch -D the_local_branch
    删除远端分支(if you know what you are doing!)
    git push origin :the_remote_branch
    查看远端分支
    git branch -a
    获取远端分支
    git fetch,可以将远程分支信息获取到本地
    git fetch origin master
    git fetch origin zyb/certainBranch
    git checkout -b local-branchname origin/remote_branchname 就可以将远程分支映射到本地命名为local-branchname 的一分支


    【测试机搞一把】
    git clone http://code.huawei.com/cloud-service-dev-team-devops/cloudwatch.git


    【git 缓存http用户名&密码】
    git config --global credential.helper 'cache --timeout=2592000'
    git config --global credential.helper wincred --replace-all
    删除配置: git config --global --unset core.excludesfile
    timeout 的时间单位为秒,可以自行修改. (示例中表示缓存 30 天)
    设置完后,再使用 http 协议操作仓库时,只要输入了一次用户名和密码,在缓存时效内就不需要再输入了。
    [可参考 http://pages.huawei.com/codeclub/guides ]


    【【reset并解决冲突】】
    1. reset到需要squash的版本号
    git log ******* --graph
    git reset *******的前一个
    【这里最好把版本号记录在案,出错后还能reset回去】
    2. 更新master
    git remote update
    git pull origin master
    一般在pull origin master的时候,git会提示无法执行,并建议move或remove一些文件,这些文件如果是自己改过的就move,pull之后再拷贝回来;如果不是自己的,直接rm
    如果其建议你commit或stash,可以这样
    git stash
    git pull origin master
    git stash pop
    3. 处理conflict
    使用webstorm的GUI,右键工程任意目录或文件,选择 Git - Resolve conflicts
    Changes to be committed:
    如果是自己的,不用管了;
    如果不是自己修改的,使用 git reset HEAD <file> ... 撤销[从工作区放回暂存区]
    Changes not staged for commit:
    如果是自己的,使用 git add <file> ...
    如果是自己删除的,使用 git rm <file> ...
    【Attention:git add/rm 都会被提交】
    如果不是自己修改的,使用 git checkout -- <file>... 撤销[从暂存区删除]
    Untracked files:
    如果是自己的,使用 git add <file> ...
    否则,忽略
    4. 提交并推到远端
    git commit -m "comments" 
    git push origin zyb/FirstCommit -f [由于使用了reset,版本号已经不符合要求了,所以-f]


    【【git stash】】
    git stash list
    git stash pop
    git stash apply stash@{1}

    git reset --hard origin/master
    以后如果不小心在master上改代码了,可以用这个恢复本地的master

    git reset --hard HASH #返回到某个节点,不保留修改。
    git reset --soft HASH #返回到某个节点。保留修改

    【Your branch is ahead of 'origin/master' by 3 commits.】
    You get that message because you made changes in your local master and you didn't push them to remote. You have several ways to "solve" it and it normally depends on how your workflow looks like:

    In a good workflow your remote copy of master should be the good one while your local copy of master is just a copy of the one in remote. Using this workflow you'll never get this message again.
    If you work in another way and your local changes should be pushed then just git push origin assuming origin is your remote
    If your local changes are bad then just remove them or reset your local master to the state on remote git reset --hard origin/master

  • 相关阅读:
    java中的各种Queue
    关闭线程的一些问题
    Exchanger
    文件锁FileLock
    StringBuffer和String需要注意的
    maven出现:Failed to execute goal on project ...: Could not resolve dependencies for project ...
    pringboot pom文件引入本地jar包和对其打jar包
    SpringBoot热部署的两种方式
    idea 自动导入包和自动将没用的包去除
    springCould:使用Feign 实现声明式服务调用
  • 原文地址:https://www.cnblogs.com/newcoder/p/7268986.html
Copyright © 2011-2022 走看看