工作必备:

【更新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. ZOJ 3332 Strange Country II (竞赛图构造哈密顿通路)

    链接:http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=3332 本文链接:http://www.cnblogs.com/Ash-l ...

  2. Tarjan求LCA总结

    Tarjan算法向上标记法:从x向上走到根节点,并标记所有经过的点从y向上走到根节点,当第一次遇到已标记的节点时,就找到了LCA(x, y)对于每个询问,向上标记法的时间复杂度最坏为O(n) 在深度遍 ...

  3. DP(悬线法)【P1169】 [ZJOI2007]棋盘制作

    顾z 你没有发现两个字里的blog都不一样嘛 qwq 题目描述-->p1169 棋盘制作 题目大意 给定一个01棋盘,求其中01交错的最大正方形与矩形. 解题思路: 动态规划---悬线法 以下内 ...

  4. POJ1679 The Unique MST(Kruskal)(最小生成树的唯一性)

    The Unique MST Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 27141   Accepted: 9712 D ...

  5. NGUI_Sprites

    一.UI Sprites 控件: Sprites控件是NGUI的基础控件,几乎可以这么说所有的控件都可以基于Sprites控件添加 Box Collider然后进行附加相关的脚本组件来达到想要的插件效 ...

  6. AtCoder - 2705 Yes or No

    Problem Statement You are participating in a quiz with N+M questions and Yes/No answers. It's known ...

  7. Github上的iOS资料-个人记录

    动画 awesome-ios-animation收集了iOS平台下比较主流炫酷的几款动画框架 RCTRefreshControlqq的下拉刷新 TBIconTransitionKiticon 的点击动 ...

  8. NSNotificationCenter监听TextField文字变化

    注册 1: NSNotificationCenter.defaultCenter().addObserver(self, selector: "textDidChange", na ...

  9. 小二助手-react.js分块加载

    小二助手在线演示地址:http://118.25.217.253:8000  账号test 密码123 小二助手是用material-ui开发的,感觉国内使用的人数不是特别多,所以创建了一个qq交流群 ...

  10. Key-Value Observing (键值监測)

    Key-Value Observing (键值监測) 简单介绍 KVO是一套当目标对象的属性值改变时观察者对象能够接受到通知的机制.必须先理解KVC才干更好的理解KVO,前者是后者的实现基础. 这种通 ...