Git在线练习--前辈的轮子
工作中使用总结,很早之前在CSDN博客上写过一篇,加上新的,重新再掘金上再写一篇吧,为所谓重复造轮子,只是为了让自己再熟悉下,总结下。
本地创建ssh key:
ssh-keygen -t rsa -C "your_email@youremail.com"
vim ~/.ssh/id_rsa.pub // key的保存地址
Config(user name、email、缓存大小) :
git config --global user.name "your name"
git config --global user.email "your_email@youremail.com"
git config -l // 查看所有git配置
vim .git/config // 查看git的配置文件
git config http.postBuffer 10240000 // 设置缓存大小
添加远程地址:
git remote add upstream git@github.com:yourName/yourRepo.git
git remote
git fetch remoteName
git fetch -p(删除相应分支) upstream(remote name) // 这将更新名称为upstream 的远程repo上的所有branch的最新commit-id,将其记录,但是不会pull下来
or
git fetch upstream branchName // 某个分支
设置对应的远程分支
git branch --set-upstream-to=<upstreamName>/<branch> <CurrentBranch>
// 然后就是拉取了
git pull upstream branchName
git pull // 设置了本地分支对应的远程分支后,git pull后的远程分支可以省略
Branch
git branch // 显示本地所有分支
git branch -a/--all // 显示所有remotes下的所有分支
git checkout branchName // 切换到branchName分支
git checkout -b branchName // 在当前分支的基础上新建branchName分支
git checkout -D branchName // 删除branchName分支
// 删除远程分支
git branch -r -d origin/branchName
git push origin:branchName
提交:
git commit -m "Detail"
or
git commit
:w
:qa! / :wq
上传:
git push origin master == git push origin HEAD:master
git push -f origin master // -f 强制推送,慎用
其他
git status 目录路径(./) // 显示该目录下所有有改变的文件
git diff 目录路径或者具体的文件路径 // 显示目录路径下所有文件或者具体文件的改动
git checkout 目录路径/具体文件路径 // 丢弃改动
Question
1. clone git 项目到一个非空目录:
1). 进入非空目录,假设是 /workdir/project
2). git clone --no-checkout git@github.com:tuchuantao/Todo.git temp
3). mv temp/.git . #将 temp 目录下的 .git 目录移到当前目录
4). rmdir temp
5). git reset --hard HEAD
2.Commit后,提交了merge,但是有同事你commit之后有提交,并且进了,此时有冲突
1). git fetch upstream branchName // 先fetch相应的分支
2). git rebase // 假如此时有冲突,会显示,解决冲突后 git rebase --continue,没有当然更好
©爱穿衬衫的程序员