命令
命令 | 含义 |
---|---|
git init | 初始化仓库 |
git status | 查看状态 |
git add | 添加文件 |
git commit -m ‘commit file’ | 提交file |
git log [–graph][–pretty=oneline][–abbrev-commit] | 查看记录 |
git reflog | 命令历史 |
git reset –hard HEAD^ | 回退到上一个版本 |
git reset –hard commit_id | HEAD到某个版本 |
git diff [HEAD – ] file | 对比差异 |
git checkout – file.m | 丢弃工作区修改 |
git reset HEAD file.m | 清空暂存区 |
git rm file.m | 删除文件 |
git remote add origin git@github.com:path/repo.git | 关联github仓库 |
git remote -v | 查看远程仓库信息 |
git push -u origin master | **推送**mster分支到远程仓库 |
git clone git@github.com:path/repo.git | 克隆远程仓库 |
branch | |
git branch | 查看当前分支 |
git branch newBranch | 创建newBranch分支 |
get checkout newBranch | 切换到newBranch分支 |
git checkout -b newBranch | 创建并切换到newBranch分支 |
git merge [–no-ff] [-m ‘message’] newBranchf | **合并**newBranch分支到当前分支,–no-ff表示no-fastward, 可以看出曾经做过的合并 |
git branch -d newBranch | 删除分支 |
git branch -D newBranch | 强制删除分支(未合并分支时,-d无法删除) |
git checkout -b newBranch origin/newBranch | 根据远程仓库的newBranch分支创建newBranch分支 |
git branch –set-upstream newBranch origin/newBranch | newBranch分支关联远程仓库的分支 |
pull | |
git pull | 更新远程仓库 |
stach | |
git stash | 保存现场 |
git stash list | stash列表 |
git stash apply [stash@{0}] | 恢复不删除 |
git stash drop | 删除stash |
git stash pop | |
tag | |
git tag | |
git tag v1.0 [commit_id] [-m ‘message’] | 打标签 |
git show [tag_name] | 查看标签信息 |
git -s v1.1 [-m ‘message’] [commit_id] | PGP签名 |
git push origin 1.1 | 推送标签 |
git push origin –tags | 推送所有标签 |
git tag -d v1.1 | 删除标签 |
git push origin :refs/tags/v1.1 | (先用上一行删除本地标签)删除远程标签 |
config | |
git config –global alias.st status | 创建别名(用于简写) |
常用设置
- 设置ignore文件
- 在git仓库主目录中添加
.gitignore
文件,模版 - 在本地commit
.gitignore
文件
- 在git仓库主目录中添加
- config文件
- 当前仓库:
.git/config
- 当前用户:
~/.gitconfig
- 当前仓库:
打开颜色
git config --global color.ui true
- 或者设置cofig文件
[color] ui = true