### git常用命令 | |
~~~ | |
git pull --rebase | |
从服务器获得更新 | |
git status | |
查看本地修改 | |
git add .git add xxx | |
添加本地的修改 | |
git rm xxx | |
删除一个本地修改 | |
git commit | |
提交本地修改,但没有上传到服务器,只是本地的记录,git commit --amend,修改上个commit的log信息,已经push到服务器的无效。 | |
git rebase -i | |
如git rebase -i HEAD~3 ,修改或合并多个本地commit。 | |
git push | |
把 本地的修改更新到服务器 | |
git log | |
查看修改记录 | |
git branch -av | |
查看分支信息 | |
gitk | |
GUI的git log | |
git remote -v | |
查看仓储路径 | |
~~~ | |
### 为什么要扔掉svn? | |
1. svn是必须在线用,没办法本地管理,不方便,本地也就能看看改动啥了。 | |
2. svn每个动作都要生成版本,创建个文件夹也记录,且版本记录无法清除 | |
3. 每个目录下都有.svn,太乱了,git只有在根目录有个.git ,所有记录都在这个.git中 | |
从多方面看,git更加灵活,svn是旧时代的产物,有些老的开源项目还在用,但很多都开始转到git了。 | |
### 基本概念 | |
commit, tree, blob | |
branch, tag, reflog | |
commit DAG | |
working directory, stage area, object database | |
使用git,有两个概念至关重要: DAG (有向无环图) 和 stage area. 这两个概念正是git的难学与强大之处。 | |
只要你理解了这两个概念,并围绕这两个概念来理解git的命令,你会发现,其实git相当简单。 | |
DAG: git的历史是一个DAG,图的每个节点代表一个commit, 而每次提交(git commit)都是在修改这个DAG. 而branch, tag仅仅是指向这个DAG的某个节点的一个指针(pointer, reference). | |
<http://www.gitready.com/beginner/2009/02/17/how-git-stores-your-data.html> | |
<http://eagain.net/articles/git-for-computer-scientists/> | |
stage area: 介于working copy和object store之间的区域。”git add”将数据临时存于 stage area, “git commit”将 stage area的数据存储到 object store | |
<http://www.gitready.com/beginner/2009/01/18/the-staging-area.html> | |
### 参考链接 | |
[visual git guide](http://marklodato.github.com/visual-git-guide/)以图形的形式解释了常用的git命令,强烈建议看看。 | |
[Git Reference](http://gitref.org/) | |
<http://github.com/guides/git-cheat-sheet> | |
<http://ktown.kde.org/~zrusin/git/git-cheat-sheet.svg> | |
[Interactive Git cheatsheet](http://www.ndpsoftware.com/git-cheatsheet.html) | |
### 实践经验 | |
和中心仓储同步时,尽量使用 “git pull –rebase” 而不是 “git pull”,后者会导致merge,而盲目的merge会导致历史很难看 | |
提交的粒度应该比较小,且是独立的功能单元 | |
commit message的格式为 比较短的 标题 + 空行 + 详细描述 | |
commit message的编码应为utf8,若在git bash下提交,vim默认配置下其编码为gbk (:set fileencoding? 可查看编码),所以请使用英文,禁止使用中文提交 | |
### 高级用法 | |
git cherry-pick 3dfe | |
git revert 3dfe | |
git grep ‘foo’ | |
git log -p | |
git log -g master # reflog | |
git log –format=oneline | |
git shortlog origin/master.. | |
git rebase -i origin/master | |
### 加入QQ群学习交流(GIT高手更高效):260858091 |
git 使用教程,常用命令
精选 转载
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Docker 常用命令
docker常用命令;包含image、container、network、volume、dockerfile、compose file等常用操作
docker image container network -
[git] git 常用命令
【代码】[git] git 常用命令。
git 远程分支 重命名 -
【Git】Git 常用命令
Git 常用命令使用
git 本地库 暂存区 -
git使用及常用命令
1.Git子模块使用情况:例如Android系统代码和app之间可以使用这种submod
git github branch 版本管理 服务器