1.简介
linus用c写的分布式版本控制系统,起初用来管理linux系统的源码。
2.安装
sudo apt-get install git
3.创建版本库(repository)
mkdir gitTest
cd gitTest
git init
4.添加文件到版本库
告诉github你是谁
git config --global user.email "email"
git config --global user.name "passwd"
告诉git把文件添加到版本库
git add readme.txt
告诉git把文件提交到版本库
git commit -m "write a readme file"
5.查看版本库的状态
git status
6.查看文件被修改的地方
git diff
7.查看提交日志
git log
git log --pretty=oneline
8.版本回退,HEAD表示当前版本,HEAD^表示上一个版本,HEAD^^表示上上一个版本,再多了可以用HEAD~100等
git reset --hard HEAD^
9.撤销位提交的修改
git checkout --readme.txt
10.删除文件
git rm hello.txt
11.将本地版本库同步到远程浏览器的github上:
git remote add origin
https://github.com/yourname/mygitproject.git
git push -u origin master/以后提交:git push origin master
12.从远程库克隆
ssh方法比较快,不需要每次输入推送口令:
git clone git@github.com:
yourname/hello-world.git
https方法:
git clone
https://github.com/
yourname/hello-world.git
13.分支管理
创建新的分支dev,并切换到分支dev
git checkout -b dev
或
git branch dev
git checkout dev
查看当前分支
git branch
合并某分支到当前分支
git merge dev
删除分支
git branch -d dev
14.将本地版本库push到远程可能会遇到的问题:
You may want to first integrate the remote changes before pushing again.意思是本地版本和主干上的有差异,让你先pull远端的版本,解决了冲突才能push,解决方法如下:
1.先合并
git pull origin master --allow-unrelated-histories
2.再重新push
git push origin master