Git 常见命令的使用

ssh-key

//1.生成ssh-key(在用户家目录.ssh文件下)
ssh-keygen -t rsa -C "Z-Beatles@waynechu.cn"
//2.重命名ssh-key
cp ~/.ssh/id_rsa.pub ~/.ssh/Z-Beatles@waynechu.cn.pub
//3.添加public key到github

init repo

cd 'repo'
//本地初始化仓库
git init
//创建远程仓库
git remote add origin git@github.com:Z-Beatles/reponame.git
//把文件添加到暂存区
git add .
//把暂存区内容提交到当前分支
git commit -m "reason"
//推送到远程服务器
git push origin master

clone repo

//Clone with SSH
git@github.com:Z-Beatles/MobileSafe.git
//Clone with HTTPS
https://github.com/Z-Beatles/MobileSafe.git

分支管理 branch

//查看分支
git branch
//创建分支
git branch 'newbranch'
//切换分支
git chechout 'branchname'
//创建并切换到该分支
git checkout –b 'branchname'
//合并某分支到当前分支
git merge 'branchname'
//删除分支
git branch -d 'branchname'
//强制删除某个分支 (未被合并的分支被删除的时候需要强制)
git branc -D 'branchname'

查看文件 diff

//比较当前文件和暂存区文件差异
git diff <file>
//比较两次提交之间的差异
git diff <id1><id1><id2>
//在两个分支之间比较
git diff <branch1>..<branch2>
//比较暂存区和版本库差异(默认)
git diff --staged
//比较暂存区和版本库差异
git diff --cached
//仅仅比较统计信息
git diff --stat

暂存管理 stash

//暂存
git stash
//列所有stash
git stash list
//恢复暂存的内容
git stash apply
//删除暂存区
git stash drop

Git远程仓库管理

//查看远程服务器地址和仓库名称
git remote -v 
//查看远程服务器仓库状态
git remote show origin
//添加远程仓库地址
git remote add origin git@github.com:Z-Beatles/reponame.git
//设置远程仓库地址 (用于修改远程仓库地址)
git remote set-url origin git@github.com:Z-Beatles/reponame.git
//删除远程仓库
git remote rm <repository>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值