git个人使用记录整理

版权声明: https://blog.csdn.net/william_n/article/details/80288051

占坑/

填坑/---------------------------------------------------------2018.5.27 

环境:win10 专业版                                                                                                                                                             recorder : william ning

默认:已经安装git.[git bash]所有操作均在git bash 中

1.基本的使用

git add 文件名[相对路径]  或者 git add .

git  commit -m "备注信息"

git pull 远程仓库名[默认为origin,可修改]  分支名  //提交代码之前先要拉取远程仓库相应分支代码 [也不是必须先要pull,可以直接push,如果报了冲突,会提醒需要git pull 然后解决冲突,之后push]

git push 远程仓库名[默认为origin,可修改]  分支名  //如果有冲突解决完,按照git add/commit  之后push 没有冲突,成功push即可.

2.git 分支操作

添加远程分支 : git remote add upstream <Nick Gitlab 地址>  //upstream是远程仓库名 默认是origin  

备注: 这里用的是GitLab,或者GitHub均可,上述命令均使用,但若用微软TFS,则需要使用 **** 命令暂时未记住,稍后补上.

查看分支:git branch  [--list]   //参数可选

创建分支:git branch <name>

切换分支:git checkout <name>

创建+切换分支:git checkout -b <name>

合并某分支到当前分支:git merge <name>

删除分支:git branch -d <name>   //如果尚未是尚未合并的分支,需要用git branch -D <name>   git一般常有提示,请认真阅读英文提示信息,常会有下步思路.

3.git 版本回退

本地仓库版本回退: 

git log [--oneline]  //查看提交记录,并记下要回退的commit id

git reset --hard  commit id  //commit id即上面对应的commit id 如:f634478d2f3d514b5ed77f6b1c8bd5533779fc21 

本地仓库回退至远程仓库版本: 

git reset --hard  commit id  //commit id 是远程仓库commit id,可以到远程仓库中查看.如 gitlab中8861eee5  本地commit id 与远程仓库commit id 明显长度不同,应为不同的id.

4.git rebase合并多次commit

git log   或者git log --oneline  [推荐使用后者,不过看不到都是谁的提交]

//之后使用wq或者q均可. //离开可视模式.便可以重新输入命令

git rebase -i HEAD~4   //4表示要合并的提交的数量,最新的四个[从下往上数,最新的提交在下面,可以通过提交时间来确认]

git rebase -Idevelop  //develop是基准线  rebase即重新设置基准线,即有参考才行

git add .

git rebase--continue

git log //查看确认

取消git rebase 命令 //即取消rebasing状态

git rebase --abort   

详细参考:

使用git rebase合并多次commit  : https://blog.csdn.net/yangcs2009/article/details/47166361

聊下 git rebase -I  : 

https://www.cnblogs.com/wangiqngpei557/p/5989292.html

5.webhook 的使用[未使用到,暂不记录] 

在gitlab 中使用webhook 实现php 自动部署git 代码

参考:

https://segmentfault.com/a/1190000009866784

https://segmentfault.com/a/1190000011561808  //比较推荐

https://www.cnblogs.com/mengyu/p/6414494.html

Gitlab上hooks:

https://code.***.io/william_ning/d****/settings/integrations

https://code.***.io/nick_cai/d****/settings/integrations//猜测

6,后续补充/




备注:

新手一枚,又是个人实践记录,并不能保证一定正确,供以参考,欢迎文明指正错误.


猜你喜欢

转载自blog.csdn.net/william_n/article/details/80288051