1.迁出某个文件到本地
git pull origin master
git checkout origin/master .
2.查看工作区与暂存区中文件做了哪些修改?
git add test.txt
git commit -m “add test.txt” #或者 git commit test.txt -m “add test.txt"
git diff HEAD - - test.txt
3.在工作区修改了某个文件,但是想丢弃这些修改,可以使用
git checkout - - file
4.rm file表示在工作区中删除,暂存区还存在file
git rm file 表示工作区和暂存区都删除, 远程库还会有该文件(使用git rm操作后,可以使用git reset HEAD - - file 同步到暂存区);使用git rm file 后 远程库还存在file,因此需要使用git push操作同步
从暂存区同步文件到工作区 git checkout - - file
5.关联&同步操作
关联:
本地关联到远程
git remote add origin git@github.com:用户名/XXX.git
远程关联到本地
git clone git@github.com:用户名/XXX.git
同步:
本地仓库同步到github
git push origin master
远程仓库同步到本地
git pull origin master
6.恢复到某个版本
MacBook-Pro:nonEBusiness lming_08$ git log
commit 0dd6b70c513932302efcad79ad3a0751c6d07c30
Author: Liang.Ming
Date: Wed Oct 21 18:08:22 2015 +0800
XXXX
commit 49fda092dbd436cdf77d011bce599e8d3d659ce8
Author: Liang.Ming
commit 0dd6b70c513932302efcad79ad3a0751c6d07c30
Author: Liang.Ming
Date: Wed Oct 21 18:08:22 2015 +0800
XXXX
commit 49fda092dbd436cdf77d011bce599e8d3d659ce8
Author: Liang.Ming
Date: Tue Oct 13 11:44:06 2015 +0800
MacBook-Pro:nonEBusiness lming_08$ git reset --soft 49fda092dbd436cdf77d011bce599e8d3d659ce8
git reset - -soft xxx
工作区文件不变,版本号恢复到xxx;这种情况一般是希望增量式修改,然后一次commit,以便于在远程界面上显示只有一次commit
git reset - -hard xxx
工作区文件和版本号恢复到xxx ;这种情况就是完全撤销
codereview时创建新的revision
arc diff --create
7.当前版本低于远程库版本
error: failed to push some refs to 'git@github.com:lming08/GitTest.git'
hint: Updates were rejected because the tip of your current
branch is behind
可以先保存修改,然后pull下来,再merge