git使用(常用的命令)

Git是什么?

Git是目前世界上最先进的分布式版本控制系统(没有之一)。

建立版本库:

[python]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. $ mkdir gittest  
  2. $ cd gittest  
  3. $ pwd  
  4. $ git init  

撤销修改

[python]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. $ vi a.txt(添加内容)  
  2. $ cat a.txt  
  3. $ git checkout -- a.txt  

如果你已经add了,那么如何撤销修改呢

[python]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. $ vi a.txt(添加内容)  
  2. $ cat a.txt  
  3. $ git add a.txt  
  4. $ git status<pre name="code" class="python">$ git remote add origin git@github.com:michaelliao/learngit.git  

$ git reset HEAD^ a.txt$ git checkout -- a.txt
 

删除修改

[python]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. $ vi a.txt(添加内容)  
  2. $ cat a.txt  
  3. $ git add a.txt  
  4. $ git commit -m "a3"  
  5. $ git status  
  6. $ rm a.txt(不同意使用)  
建议使用:
[python]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. $ vi a.txt(添加内容)  
  2. $ cat a.txt  
  3. $ git add a.txt  
  4. $ git commit -m "a3"  
  5. $ git status  
  6. $ git rm a.txt  
  7. $ git commit -m "a4"  

git远程仓库,生成一个.ssh文件(在你的C盘中用户里边)

[python]  view plain  copy
  1. $ ssh-keygen -t rsa -C "youremail@example.com"  
添加远程库

在github上建立一个仓库,把你本地的仓库同步到github上

[python]  view plain  copy
  1. $ git remote add origin git@github.com:michaelliao/learngit.git  

[python]  view plain  copy
  1. $ git push -u origin master  

推送成功后,可以立刻在GitHub页面中看到远程库的内容已经和本地一模一样:

[python]  view plain  copy
  1. $ git push origin master  

从远程库克隆

git clone 克隆地址

分支管理

首先,我们创建dev分支,然后切换到dev分支:

[python]  view plain  copy
  1. $ git checkout -b dev  
  2. Switched to a new branch 'dev'  

git checkout命令加上-b参数表示创建并切换,相当于以下两条命令:

[python]  view plain  copy
  1. $ git branch dev  
  2. $ git checkout dev  
  3. Switched to branch 'dev'  
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值