1. git帮助文档
$git
usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
<command> [<args>]
These are common Git commands used in various situations:
start a working area (see also: git help tutorial)
clone Clone a repository into a new directory
init Create an empty Git repository or reinitialize an existing one
work on the current change (see also: git help everyday)
add Add file contents to the index
mv Move or rename a file, a directory, or a symlink
reset Reset current HEAD to the specified state
rm Remove files from the working tree and from the index
examine the history and state (see also: git help revisions)
bisect Use binary search to find the commit that introduced a bug
grep Print lines matching a pattern
log Show commit logs
show Show various types of objects
status Show the working tree status
grow, mark and tweak your common history
branch List, create, or delete branches
checkout Switch branches or restore working tree files
commit Record changes to the repository
diff Show changes between commits, commit and working tree, etc
merge Join two or more development histories together
rebase Reapply commits on top of another base tip
tag Create, list, delete or verify a tag object signed with GPG
collaborate (see also: git help workflows)
fetch Download objects and refs from another repository
pull Fetch from and integrate with another repository or a local branch
push Update remote refs along with associated objects
2. 配置
用户名和邮箱
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
给git指令添加颜色
git config --global color.ui true
3. 常用命令
- 创建版本——
git init
- 查看状态——
git status
- 提交改动到缓存区,生成快照——
git add <file>
- 提交缓存区的快照到版本库——
git commit -m '<tag_name>'
- 查看改动(未git add进入缓存区前)——
git diff <file>
- 查看日记——
git log --pretty=oneline --abbrev-commit
- 版本回滚——
git reset --hard 4810735
- 查看所有版本——
git reflog
- 撤销修改(未git add进行缓存区前)——
git checkout -- <file>
- 撤销修改到缓冲区前(已经git add),然后在用
git checkout
撤销修改——git reset HEAD <file>
- 提交被删除的文件到缓存区——
git rm <file>
4. 标签管理
命令git tag <tagname>
用于新建一个标签,默认为HEAD,也可以指定一个commit id;
命令git tag -a <tagname> -m "blablabla..."
可以指定标签信息;
命令git tag
可以查看所有标签。
命令git push origin <tagname>
可以推送一个本地标签;
命令git push origin --tags
可以推送全部未推送过的本地标签;
命令git tag -d <tagname>
可以删除一个本地标签;
命令git push origin :refs/tags/<tagname>
可以删除一个远程标签。
5. 分支管理:
查看分支:git branch
创建分支:git branch <name>
切换分支:git checkout <name>
创建+切换分支:git checkout -b <name>
合并某分支到当前分支:git merge <name>
删除分支:git branch -d <name>
查看分支:git log --graph --pretty=oneline --abbrev-commit
参考文档:
廖雪峰《Git教程》 https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000
git博客
http://bioinfostar.com/2018/06/15/%E5%AD%A6R%E5%AD%A6%E5%88%9D%E9%98%B6-03-R-Git%E5%92%8CGithub-1/
http://bioinfostar.com/2018/06/15/%E5%AD%A6R%E5%AD%A6%E5%88%9D%E9%98%B6-03-R-Git%E5%92%8CGithub2/
github配置
获取SSH密钥
- id_rsa私钥
- id_rsa.pub 公钥
ssh-keygen -t rsa -C "your_own_email@example.com"
将公钥放置github的Settings - SSH and GPG keys - New SSH key
- 自定义title
- 粘贴公钥Add SSH key
远程库
创建远程库
在github网页上操作
上传到远程库
# 将本地git文件夹或者git clone克隆远程库后,在里面进行修改操作,然后,提交,上传版本库
git add README.md
git commit -m "first commit"
# 添加远程地址
# yourName和yourRepo表示你再github的用户名和刚才新建的仓库
git remote add origin git@github.com:yourName/yourRepo.git
# 将本地master推送到远程库
git push origin master
# 输入用户名和密码,即可同步
- 当前目录下的,.git/config,可以添加远程库的地址
- git push命令会将本地仓库推送到远程服务器。
- git pull命令则相反。
- git add -A 一次性将所有修改都添加
- .gitignore 为忽略伟健
克隆远程库
git clone git@github.com:USERNAME/REPO_NAME.git
- USERNAME改为你想克隆的仓库的创建者,
- REPO_NAME改为仓库名称