git常见操作

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
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 



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值