工作必备:

【更新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

Git使用笔记2的更多相关文章

  1. Git学习笔记与IntelliJ IDEA整合

    Git学习笔记与IntelliJ IDEA整合 一.Git学习笔记(基于Github) 1.安装和配置Git 下载地址:http://git-scm.com/downloads Git简要使用说明:h ...

  2. Git学习笔记(10)——搭建Git服务器

    本文主要记录了Git服务器的搭建,以及一些其他的配置,和最后的小总结. Git远程仓库服务器 其实远程仓库和本地仓库没啥不同,远程仓库只是每天24小时开机为大家服务,所以叫做服务器.我们完全可以把自己 ...

  3. Git学习笔记(四)

    一.忽略特殊文件 在Git工作区的根目录下创建一个特殊的.gitignore文件,然后把要忽略的文件名填进去,Git就会自动忽略这些文件. 不需要从头写.gitignore文件,GitHub已经为我们 ...

  4. git 学习笔记6--remote & log

    git 学习笔记6--remote & log 创建SSH Keys ssh-keygen -t rsa -C "1050244110@qq.com" 本地关联远程 git ...

  5. 《Pro Git》笔记3:分支基本操作

    <Pro Git>笔记3:Git分支基本操作 分支使多线开发和合并非常容易.Git的分支就是一个指向提交对象的可变指针,极其轻量.Git的默认分支为master. 1.Git数据存储结构和 ...

  6. git使用笔记(三)(图文说明) 图解提交更改内容的不同方式,涉及代码

    此步之前的工作和示例请参考以下帖子: git使用笔记(一)Git的下载与配置 git使用笔记(二) 如何把GitHub上项目同步到本地 -------------------------------- ...

  7. git入门笔记汇总——(廖雪峰博客git入门)

    本文内容是对廖雪峰老师Git教程做的笔记,外加一些自己的学习心得,还抱着学以致用的心态来实践一番 如有显示错误 请移步本人github:git教程小结 Git学习笔记 Git简介 安装Git 创建版本 ...

  8. Git学习笔记---协作的一般流程

    一般的操作流程 1.pull 王小坤与另一个同事张大炮一起开发一个项目,张大炮昨天修改了数据库读写的api,优化了执行速度,并把read()函数改名成了Read(),下午下班之前把这些代码push到服 ...

  9. 【转帖】Git学习笔记 记录一下

    本文内容参考了廖雪峰老师的博文,并做了适当整理,方便大家查阅. 原帖地址 https://wangfanggang.com/Git/git/ 常用命令 仓库初始化 - git init 1 git i ...

  10. 【Git 使用笔记】第四部分:git在公司中的开发流程

    先声明几个变量 仓管A:主分支,只有master分支仓管B:开发分支,只有各个业务开发分支   仓管B fork 于 A 如下图 为了保证 代码的稳定性,只有 仓管B中的某个分支测试完毕并进行了代码r ...

随机推荐

  1. golang笔记:cookie

    在同一个问题上栽了两次,以后碰到cookie出问题多半都是因为这个. Request.Cookie(name)取Cookie的时候,返回值只有name和value cookie.go cookies ...

  2. 洛谷——P3913 车的攻击

    P3913 车的攻击 题目描述 N \times NN×N 的国际象棋棋盘上有KK 个车,第ii个车位于第R_iRi​行,第C_iCi​ 列.求至少被一个车攻击的格子数量. 车可以攻击所有同一行或者同 ...

  3. 8、Flask实战第8天:add_url_rule和app.route原理

    之前我们使用@app.route这个装饰器来把视图函数和url绑定 @app.route('/') def hell_world(): return 'hello world' 而且我们可以通过url ...

  4. [BZOJ 1293] 生日礼物

    Link: BZOJ 1293 传送门 Solution: 这题直接上尺取法就行了吧 先将每种颜色第一个放入优先队列,用$mx$维护当前的末尾位置 每次取出第一个颜色,更新答案.将其下一个放入队列中去 ...

  5. 【计算几何】URAL - 2101 - Knight's Shield

    Little Peter Ivanov likes to play knights. Or musketeers. Or samurai. It depends on his mood. For pa ...

  6. Scala零基础教学【1-20】

    基于王家林老师的Spark教程——共计111讲的<Scala零基础教学> 计划在9月24日内完成(中秋节假期之内) 目前18号初步学习到25讲,平均每天大约完成15讲,望各位监督. 初步计 ...

  7. fidder模拟post提交到PHP遇到的问题

    http头必须带上Content-type: application/x-www-form-urlencoded  之后 ,php 才能接收到post数据 1. 用php://input可以很便捷的取 ...

  8. cssz中<a>标签鼠标选中去除选中边框

    IE: <a href="#" hidefocus="true"></a> 非IE: a:focus { outline:none; } ...

  9. hdu4565之矩阵快速幂

    So Easy! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total S ...

  10. Flex页面跳转的五种实现方式

    Flex页面跳转有很多值得学习的地方,本文向大家介绍一下Flex页面跳转的几种方式,主要包括五种方式,这里为大家一一介绍. AD:   在学习Flex的过程中,你可能会遇到Flex页面跳转的概念,这里 ...