git 命令
查看git版本
git --version
初始化仓库
git init
添加远程仓库
git remote add origin https://git.oschina.net/null_723_7877/git-test.git
查看远程仓库信息
git remote
git remote -v
git ls-remote
获取远程仓库信息
git fetch #默认获取所有仓库所有分支信息
git fetch origin master #获取指定仓库指定分支信息
git fetch origin #获取制定仓库所有分支信息
查看分支信息
git branch -r#查看远程仓库分支
git branch -a#查看所有分支
合并远程仓库分支
git merge origin/master
向中央仓库推送
git push --set-upstream origin master
git push -u origin master #简写方式
克隆仓库
git clone https://git.oschina.net/null_723_7877/git-test.git
git clone https://git.oschina.net/null_723_7877/git-test.git www #重新制定文件名
从中央仓库中拉取
git init
git remote add origin https://git.oschina.net/null_723_7877/git-test.git
git pull origin master
git init
git remote add origin https://git.oschina.net/null_723_7877/git-test.git
#git pull origin master 相当于下面两条命令
git fetch origin master
git merge origin/master
#git clone相当于下面的命令
git init
git remote add origin https://git.oschina.net/null_723_7877/git-test.git
git fetch origin # 获取origin所有分支信息
git merge origin/master
获取远程分支到本地
$ git checkout -b dev origin/dev
git init
git remote add origin https://.../.git
git checkout -b dev
git merge origin/dev#合并分支
git branch -u origin/dev dev
$ git branch -vv
* dev a5a5534 [origin/dev] 111
绑定本地和远程分支
$ git branch -u origin/dev dev
#相当于 git branch --set-upstream-to=origin/dev dev
撤销文件git checkout(默认从暂存区中检出文件,也可以从仓库去HEAD或制定版本中检出)
修改,和暂存区一样 git checkout<file>默认从暂存去中检出
撤销文件修改,和仓库一样 git checkout HEAD<file>从上次提交中(头版本)中检出
从制定版本中检出git checkout<commit><file>
checkout还有一个作用是切换分支
比较文件git diff(默认比较暂存区文件,也可以制定仓库区HEAD或者制定版本比较)
比较工作区和暂存区差异 git diff file
比较暂存区和仓库区差异 git diff --cached file
比较工作区和仓库区差异 git diff HEAD file
比较工作区和仓库某个提交版本的差异 git diff<commit>file
比较两次提交的差异 git diff [<commit>[<commit>]] file
重置git reset
取消暂存git reset<file>
恢复暂存区和仓库区一致(工作区不变) git reset HEAD<file>
恢复工作区和仓库区一致git reset --hard恢复到和上次提交一样,放弃所有未提交的修改
恢复工作区回退到某一个版本 git reset --hard<commit>指针回退到指定版本,此版本后的所有版本历史被删除