git常用命令

[php] view plain copy

  1. 命令可以参考:  

[php] view plain copy

  1. http://www.yiibai.com/git/  

创建一个空的版本库

<?php
$arr =['a','b','c','d','e','f','h','i'];
for($arr as $val){
    echo $val;
}

?>

[php] view plain copy

  1. git init --bare 'MyFirst.git'  

克隆远程版本库

 

[php] view plain copy

  1. git clone git@**.**.**.**:/home/git/MyFirst.git  


把文件添加到本地的缓冲区

 

[php] view plain copy

  1. git add ./  

文件提交到本地的版本库

 

[php] view plain copy

  1. git commit -m 'test'  

本地代码提交到远程版本库

 

[php] view plain copy

  1. git push 远程版本库  本地版本库  

更新远程版本库内容

 

[php] view plain copy

  1. git pull <远程主机名> <远程分支名>:<本地分支名>  

查看日志

[php] view plain copy

  1. git log  

查看指定版本修改内容

 

[php] view plain copy

  1. git show 版本号  

版本回退

[php] view plain copy

  1. git reset   
  2.   
  3. 在Git中,用HEAD表示当前版本,也就是最新的提交3628164...882e1e0(注意我的提交ID和你的肯定不一样),上一个版本就是HEAD^,上上一个版本就是HEAD^^,当然往上100个版本写100个^比较容易数不过来,所以写成HEAD~100  

git 撤销工作区添加

[php] view plain copy

  1. git checkout -- readme.txt  
  2. 命令git checkout -- readme.txt意思就是,把readme.txt文件在工作区的修改全部撤销,这里有两种情况:  
  3. 一种是readme.txt自修改后还没有被放到暂存区,现在,撤销修改就回到和版本库一模一样的状态;  
  4. 一种是readme.txt已经添加到暂存区后,又作了修改,现在,撤销修改就回到添加到暂存区后的状态。  
  5. 总之,就是让这个文件回到最近一次git commit或git add时的状态  

git删除文件

 

[php] view plain copy

  1. git rm a.txt  

添加远程库

[php] view plain copy

  1. git remote add origin(版本库名称) git@***.**.**.**:/home/git/learngit.git  

查看当前的远程库

 

[php] view plain copy

  1. git remote   

[php] view plain copy

  1. git remote -v 每个远程库对应的url  

设置git用户

[php] view plain copy

  1. 第一个要配置的是你个人的用户名称和电子邮件地址。这两条配置很重要,每次 Git 提交时都会引用这两条信息,说明是谁提交了更新,所以会随更新内容一起被永久纳入历史记录:  
  2.   
  3.   
  4. $ git config --global user.name "John Doe"  
  5. $ git config --global user.email johndoe@example.com  
  6. 如果用了 --global 选项,那么更改的配置文件就是位于你用户主目录下的那个,以后你所有的项目都会默认使用这里配置的用户信息。如果要在某个特定的项目中使用其他名字或者电邮,只要去掉 --global 选项重新配置即可,新的设定保存在当前项目的 .git/config 文件里。  

创建分支

 

[php] view plain copy

  1. git branch 分支名称  会从当前版本创建一个分支  

切换分支:

 

[php] view plain copy

  1. git checkout 分支名称  

创建一个分支并且切换到该分支:

 

[php] view plain copy

  1. git checkout -b test_branch  

删除分支:

 

[php] view plain copy

  1. git branch -D 分支名  

重命名分支:

 

[php] view plain copy

  1. git branch -m 旧的分支名 新的分支名  

git合并分支到当前分支(自动提交)

 

[php] view plain copy

  1. git merge 分支名   

git合并分支到当前分支(不自动提交)

 

[php] view plain copy

  1. git merge --no-commit maint  
  2.  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值