ND-Git总结

0-git bash预配置

0.1-ssh
ssh-keygen -t rsa -C example@mail.com
cat ~/.ssh/id_ras.pub
  • gitee分项目部署(clone、pull)和个人部署(pull+push)
0.2-git config
//基于仓库
git config
//基于用户,优先于基于仓库
git config --global
//基于系统
git config --system

1-创建仓库

2-remote add或clone

//关联或克隆能起到相同效果
//1-关联远程仓库
git init
git remote add origin http/git-path
git pull origin branch_name
//2-克隆仓库
git clone <-b branch_name> http/git-path newdocument

3-pull、push

  • 本地推送分支:git push origin branch-name
  • 推送分支前最好先pull分支:git pull origin branch-name
//设置默认提交remote-repository和branch
git push -u
//不同名分支推送
git push origin HEAD:remote_branch_name
git push origin local_branch_name:remote_branch_name
//直接push不同名会给远程仓库新建分支

4-reset

//状态、修改、日志
git status
get diff (file)
git log	
//版本回退
git reset --hard HEAD^
	HEADHEAD~100
git reset --hard 1094a
	到commit id 为1094a的新提交
	git通过head指针指向切换当前版本
//后悔药
git reflog
4.1-HEAD~和^
  • HEAD~num

    //~2 向上两代;向上一代
    
  • HEAD^

    //^ 向上一代;^^ 向上两代(等价~2)
    
  • HEAD^num

    //^2 向上一代第二个parent节点;^^2 奶奶节点
    
  • 组合使用

    //~^2 奶奶节点
    

5-branch+checkout/switch

5.1-branch
  • 查看分支信息:git branch -r
  • 查看所有分支信息:git branch -a
//关联分支1
git branch --set-upstream-to=origin/remote_branch your_branch
//新建关联分支2
git checkout -b branch-name origin/branch-name
5.2-checkout/switch
//仅仅切换分支
git checkout branch_name
//-b新建并切换,加commit-hash复制本次commit到新分支
git checkout -b branch_name <hash>
//checkout文件,将add的文件移除暂存
git example.file
//switch
git switch branch_name
git switch -c branch_name <hash>

6-merge

//到主分支
git merge vice_branch
//pull/merge request
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值