Skip to content

parselife/git-userguide

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

git-guide

TOC

安装


  • linux
yum -y install git
  • macosx
brew install git
  • windows

    下载二进制安装程序. 地址

    安装后 运行命令 git 查看

⬆️ 回到目录

创建版本库

  • 创建新的版本库
git init
  • 克隆已有的版本库
git clone ssh://user@xx.com/xxx.git

⬆️ 回到目录

状态与添加提交

  • 查看当前版本库文件状态
git status
  • 添加本地文件
git add tmp.txt
  • 添加当前文件夹下文件
git add .

add 只是将文件变化提交到 暂存区

  • 提交变化
git commit -m <message>

commit 只提交暂存区(stage)内的文件变化

  • 查看变化
git diff HEAD --<file>

git diff

⬆️ 回到目录

提交记录

  • 查看所有提交记录
git log
  • 查看某个文件的提交记录
git log -p <file>
  • “追责”某个文件
git blame <file>

⬆️ 回到目录

版本回退

  • 回退到上一版本 丢弃工作区的修改
git reset --hard HEAD
  • 回退到某个指定版本
git reset --hard <commit id>

commit id 可通过 git log 进行查看

  • 回退后,重返较近的版本
git reflog 
git reset <commit id>
  • 撤销修改
git checkout HEAD <file>

用命令 git reset HEAD <file> 可以把暂存区的修改撤销掉(unstage),重新放回工作区

  • 丢弃工作区的修改
git checkout -- <file>
  • 恢复某次提交
git revert <commit id>

⬆️ 回到目录

更新与发布

  • 拉取最新修改到本地版本库
git pull <remote> <branch>
  • 把本地提交内容推送到远程库
git push <remote> <branch>

eg. git push origin master

⬆️ 回到目录

分支与标记

  • 列出所有的分支
git branch -av
  • 将工作区切换到某个分支
git checkout <branch>
  • 切换新分支
git checkout -b <new_branch>
  • 创建标记
git tag <tag_name>

命令 git tag <tagname> 用于新建一个标签,默认为 HEAD,也可以指定一个 commit id

  • 查看所有的标记
git tag
  • 删除标记
git tag -d <tag_name>

⬆️ 回到目录

About

A git user guide for beginners & command lovers(like me, hoho)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published