git 操作

1.Git 基础版

1. 常用

1.把当前目录中的文件加入到暂存区中:
	git add .
2.移除指定文件的缓存
	git rm ---cached  [fileName]
3.提交
	git commit
4.查看提交记录
	git log 	
5.查看提交的内容
	git show <commit>

2.分支操作

1.查看分支:
	git branch 
2.创建分支:
	git branch [branchName]
3.删除分支
	1.弱删除
		git branch -d
	2.强删除 (就算代码有 未合并的 也可以删除)
		git branch -D
4.创建分支并切换:
	git checkout -b  [branchName]
5.把指定分支的代码合并到当前分支上:
	git merge [branchName]

3.git tag

1.查看 所有的标签
	git tag
2.创建 标签
	git tag [tagName]
3.切换标签
	git checkout [tagName]

4.push&&pull

1. 将本地代码推到master分支
	git push origin master
2.将远程仓库最新代码来下来
	git pull origin master

5.关联 git remote

1.将本地项目(当前)与指定的项目(test)进行关联:
	git remote add origin git@github.com:test/test.git
2. 查看当前项目有哪些远程仓库	
	git remote -v

6.设置用户信息

git config --global user.name "userName"
git config --global user.email "email@163.com"

2.Git 进阶版

1.alias

1.给 checkout 起别名(co):
	git config --global alias.co checkout 
	git config --global alias.ci commit 
2.组合
	git config --global alias.psm 'push origin master'
	git config --global alias.plm 'pull origin master'
3. 显示日志详细
 	 git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
4.起别名 git lg
	git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"

2. diff

1.比较暂存区和版本库之间的差异:
	git diff
2.比较两次提交之间的差异
	git diff <$id1> <$id2>
3.比较两个分支之间的差异:
	git diff <branch1> <branch2>
4.比较 暂存区和版本库差异:
	git diff --staged

3.checkout

1.切换分支
	git checkout [branchName]
2.切换 tag
	git checkout [tagName]
3.切换commit
	git checkout   049879b781563d8772455bd6305e087a19fe1952
4. 撤销作用(没有 add)
	git checkout a.md

4.stash

1.切换分支发现本分支有修改,需提交
	1.可以使用 
	   	git commit
	 2.使用(没有使用commit)
	 	git stash
		 1.查看暂存区
		 	git stash list
		 2.还原
		 	git stash apply
		 3.删除
		 	git stash drop
		 4.还原并删除
		 	git stash pop
		 5.清空暂存区中所有的记录
		 	git stash clear

5.merge & rebase

1.语法:
	git rebase [分支名称]
	git merge [分支名称]
2.区别:
	merge 比较暴力,但是可以知道是从哪里来
	rebase 合并之后,看起来有逻辑

3. 分支操作

1.命令

1.将指定分支推送到远程仓库
	1.使用默认名称:
		git push origin [branchName]
	2.使用指定名称
		git push origin [当前分支的名称]:[指定远程分支的名称]
2.查看分支列表
	1.本地	
		git branch 
	2.远程
		git branch -r 
	3. 远程和本地的分支
		git branch -a
3.删除分支
	1.本地
		git branch -d [分支名称]
		git branch -D develop (强制删除)
	2.远程
		git push origin :[远程分支的名称]
4.把远程分支迁到本地
	git chekcout -b [本地名称]  origin/[远程名字]
5.查看分支的创建时间
	git reflog show --date=iso <branch name>

2. 分支详解

1.核心分支:
	1.master : 永远处在即将发布 (production-ready)状态
	2.develop
		最新的开发状态
2.辅助分支:
	1.feature: 开发新功能的分支,基于develop,完成后merge会develop
	2.release:准备要发布版本的分支,用来修复bug,基于develop,完成之后merge 会develop和master
	3.hotfix:修复master上的问题,等不及release版本就必须马上上线,基于master,完成 merge 回master 和 develop

3. 常用操作

1. 查看版本提交信息
	 git show  commitID;
2. 查看分支绑定
	git branch -vv
3. 分支绑定
	git push --set-upstream origin dev
git库中信息操作
1. 查看用户名及邮箱
	git config user.name
	git config user.email
2. 设置和更改用户名及邮箱
	git config --global user.name "your name"
	git config --global user.email "your email"
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值