GIT命令精简总结

2018-01-24  本文已影响0人  Cinque_Peng

一、最基本命令

1. git配置

git config --global user.name "Your Name"
git config --global user.email "email@example.com"

2. 创建文件夹与进入

mkdir learngit
cd learngit

3. 设置当前位置为git仓库

git init

4. 添加至仓库(又名版本库)

git add readme.md
git commit -m "wrote a readme file"

4. 信息查看

git status                  #当前状态
git log 
git log --pretty=oneline    #列表查看

二、远程仓库

1. 添加SSH

#创建SSH key(主目录里找到.ssh目录,里面有id_rsa和id_rsa.pub两个文件):
ssh-keygen -t rsa -C "youremail@example.com"

#登陆GitHub,“Account settings”——“SSH Keys”
#点“Add SSH Key”,填上任意Title,在Key文本框里粘贴id_rsa.pub文件的内容。    

2. 关联

git remote add origin git@github.com:******/#####.git

3. 添加推送

git push -u origin master(第二次就不用-u了)

推送到其他分支(并命名)
git push origin dev

4. 克隆

git clone git@github.com:******/#####.git

4. 查看远程库信息

git remote
#详细
git remote -v

三、版本控制

#到过去:
git reset --hard HEAD^

HEAD //表示当前版本

HEAD^ 和 git reset // 上一个版本

HEAD^^ //上上一个版本

HEAD~10 //前10个版本

#回未来(利用commit的id):
git reset --hard 3628164

#可以查到id(它记录你的每一次命令)
git reflog

#可以查看提交历史
git log

四、分支管理

查看分支:git branch

创建分支:git branch <name>

切换分支:git checkout <name>

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

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

删除分支:git branch -d <name>
上一篇 下一篇

猜你喜欢

热点阅读