工作必备:

【更新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. lunux多线程编程

    1.进程与线程 1)用户空间角度: 进程:fork()创建进程,在创建时,重新申请了内存空间,copy了父进程的所有信息. 线程:pthread_create()创建进程时,只申请自己的栈空间. 2) ...

  2. codevs 方格取数

    1043 方格取数 2000年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题解  查看运行结果     题目描述 Descri ...

  3. 带WHERE子句的UPDATE语句

    目前演示的几个UPDATE语句都是一次性更新所有行的数据,这无法满足只更新符合特定条件的行的需求,比如“将Tom 的年龄修改为12 岁”.要实现这样的功能只要使用WHERE 子句就可以了,在WHERE ...

  4. Web目录全能扫描工具DirBuster

    Web目录全能扫描工具DirBuster   Kali Linux提供的目录扫描工具DirBuster支持全部的Web目录扫描方式.它既支持网页爬虫方式扫描,也支持基于字典暴力扫描,还支持纯暴力扫描. ...

  5. Codeforces 702 D Road to Post Office

    题目描述 Vasiliy has a car and he wants to get from home to the post office. The distance which he needs ...

  6. 【分块】bzoj1901 Zju2112 Dynamic Rankings

    区间k大,分块大法好,每个区间内存储一个有序表. 二分答案,统计在区间内小于二分到的答案的值的个数,在每个整块内二分.零散的暴力即可. 还是说∵有二分操作,∴每个块的大小定为sqrt(n*log2(n ...

  7. 【MySQL笔记】: unable to connect to remote host. catalog download has failed.

    安装完MySQL之后,它每天凌晨启动一个Intaller任务,甚是烦人:   这是一个Windows的计划服务,在这里删除即可,开始/附件/系统工具/任务计划程序,把mysql的定时任务计划取消/删除 ...

  8. RxJava 2.x 理解-1

    在RxJava 1.x 系列中,讲解了RxJava的大致用法,因为现在都用RxJava 2了,所以Rxjava 1就不细讲,主要来学习RxJava 2. 基本使用: /** * rajava2 的基本 ...

  9. IntelliJ IDEA控制台输出中文乱码问题解决

    如果还不行,那么再极端的设置,在IDEA启动的时候强制设置为UTF-8: 打开增加-Dfile.encoding=UTF-8,重启Intellij IDEA 再或者直接在项目运行的时候加入UTF-8的 ...

  10. Java下String逗号数组和List<String>的互相转换

    说明:很遗憾,组装的时候只能遍历. 方法: public static String listToString(List<String> list){ if(list==null){ re ...