[php] view plain copy
- 命令可以参考:
[php] view plain copy
- 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
- git init --bare 'MyFirst.git'
克隆远程版本库
[php] view plain copy
- git clone git@**.**.**.**:/home/git/MyFirst.git
把文件添加到本地的缓冲区
[php] view plain copy
- git add ./
文件提交到本地的版本库
[php] view plain copy
- git commit -m 'test'
本地代码提交到远程版本库
[php] view plain copy
- git push 远程版本库 本地版本库
更新远程版本库内容
[php] view plain copy
- git pull <远程主机名> <远程分支名>:<本地分支名>
查看日志
[php] view plain copy
- git log
查看指定版本修改内容
[php] view plain copy
- git show 版本号
版本回退
[php] view plain copy
- git reset
- 在Git中,用HEAD表示当前版本,也就是最新的提交3628164...882e1e0(注意我的提交ID和你的肯定不一样),上一个版本就是HEAD^,上上一个版本就是HEAD^^,当然往上100个版本写100个^比较容易数不过来,所以写成HEAD~100
git 撤销工作区添加
[php] view plain copy
- git checkout -- readme.txt
- 命令git checkout -- readme.txt意思就是,把readme.txt文件在工作区的修改全部撤销,这里有两种情况:
- 一种是readme.txt自修改后还没有被放到暂存区,现在,撤销修改就回到和版本库一模一样的状态;
- 一种是readme.txt已经添加到暂存区后,又作了修改,现在,撤销修改就回到添加到暂存区后的状态。
- 总之,就是让这个文件回到最近一次git commit或git add时的状态
git删除文件
[php] view plain copy
- git rm a.txt
添加远程库
[php] view plain copy
- git remote add origin(版本库名称) git@***.**.**.**:/home/git/learngit.git
查看当前的远程库
[php] view plain copy
- git remote
[php] view plain copy
- git remote -v 每个远程库对应的url
设置git用户
[php] view plain copy
- 第一个要配置的是你个人的用户名称和电子邮件地址。这两条配置很重要,每次 Git 提交时都会引用这两条信息,说明是谁提交了更新,所以会随更新内容一起被永久纳入历史记录:
- $ git config --global user.name "John Doe"
- $ git config --global user.email johndoe@example.com
- 如果用了 --global 选项,那么更改的配置文件就是位于你用户主目录下的那个,以后你所有的项目都会默认使用这里配置的用户信息。如果要在某个特定的项目中使用其他名字或者电邮,只要去掉 --global 选项重新配置即可,新的设定保存在当前项目的 .git/config 文件里。
创建分支
[php] view plain copy
- git branch 分支名称 会从当前版本创建一个分支
切换分支:
[php] view plain copy
- git checkout 分支名称
创建一个分支并且切换到该分支:
[php] view plain copy
- git checkout -b test_branch
删除分支:
[php] view plain copy
- git branch -D 分支名
重命名分支:
[php] view plain copy
- git branch -m 旧的分支名 新的分支名
git合并分支到当前分支(自动提交)
[php] view plain copy
- git merge 分支名
git合并分支到当前分支(不自动提交)
[php] view plain copy
- git merge --no-commit maint