Git操作笔记
简介操作初始化添加文件查看状态版本回退SSH Key远程库分支保存现场多人工作标签
简介
在看了廖雪峰老师的课后,做了一些笔记,本文是对操作的归纳。
操作
初始化
git init
添加文件
git add
<file
>
git commit
-m
<message
>
查看状态
git status
git diff
版本回退
git reset
--hard commit_id
git log
git reflog
git checkout
-- file
git reset HEAD
<file
>
git rm
SSH Key
ssh
-keygen
-t rsa
-C
"youremail@example.com"
在用户主目录里找到.ssh文件,把当中的id_rsa.pub内容放到GitHub里面。
远程库
git remote add origin git@server
-name
:path
/repo
-name
.git
git push
-u origin master
git push origin master
git clone git@server
-name
:path
/repo
-name
.git
分支
git branch
git branch
<name
>
git checkout
<name
>
git
switch <name
>
git checkout
-b
<name
>
git
switch -c
<name
>
git merge
<name
>
git branch
-d
<name
>
git log
--graph
--pretty
=oneline
--abbrev
-commit
git merge
--no
-ff
-m
"<message>" <name
>
git branch
-D
<name
>
保存现场
git stash
git stash pop
git cherry
-pick
<commit
>
多人工作
git push origin
<branch
-name
>
git pull
git branch
--set
-upstream
-to
<branch
-name
> origin
git rebase
标签
git tag
-a
<tagname
> -m
"<message>"
git tag
git push origin
<tagname
>
git push origin
--tags
git tag
-d
<tagname
>
git push origin
:refs
/tags
/<tagname
>