[关闭]
@terrygmk 2020-02-14T16:31:43.000000Z 字数 1548 阅读 194

Git学习笔记

学习笔记


目录

配置

配置用户名与Email

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

配置别名

$git config --global alias.st status
$git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"

配置文件

版本管理

初始化版本库

$git init

版本回退

回到上个版本

$git reset --hard HEAD^

回到指定版本

$git reset --hard <commit_id>

日志

版本日志

$ git log

版本历史回退日志

$git reflog

文件管理

添加/修改文件

$git add
$git commit -m <message>

查看不同

工作区与缓存区的不同

$git diff [file]

工作区与版本的不同

$ git diff HEAD [file]

文件删除

确认删除

$git rm <file>
$git commit -m <message>

误删找回(即还原工作区文件)

$git restore <file>

文件还原

还原工作区文件

$git restore <file>

还原缓存区文件

$git restore --staged <file>

分支管理

查看分支列表

$git branch

创建分支

$git branch <branch_name>

删除分支

$git branch -d <branch_name>

切换分支

$git switch <branch_name>

合并分支

$git merge <branch_name>

远程仓库

GitHub配置

$ssh-keygen -t rsa -C "youremail@example.com"
还有其它一些步骤

关联远程仓库

$ git remote add origin git@github.com:michaelliao/learngit.git

推送

首次推送

$ git push -u origin master

以后推送

$ git push origin master
$ git push

从远程仓库克隆

$ git clone git@github.com:michaelliao/gitskills.git

标签管理

标签列表

$ git tag

创建标签

默认在HEAD打标签

$ git tag <tag_name>

指定 commit_id 打标签

$ git tag <tag_name> <commit_id>

删除标签

删除本地标签

$ git tag -d <tag_name>

查看标签信息

$ git show <tag_name>

删除远程标签

$git push origin :refs/tags/<tag_name>

推送标签

推送单个标签

$ git push origin <tag_name>

推送所有未推荐的标签

$ git push origin --tags

鸣谢

廖雪峰Git教程

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注