git的详细说明文档

http://www.ihref.com/read-16369.html

  • fork 后如何保持同步

http://www.tuicool.com/articles/6vayqen

git status 查看更改的文件

git diff 查看更改文件细节

git reflog 查看所有的提交记录

比较两个分支然后打成补丁

git diff 分支1 分支2 > 补丁名称

git apply 补丁名称 添加补丁

commit回滚到上一次操作

git reset --soft HEAD^

撤销某一次提交

git revert <commit_id>

git push

回滚到某一次提交

git log

git reset --hard <commit_id>

git push origin HEAD --force

设置用户名

git config --global user.name "name"

设置邮箱

git config --global user.email "email"

仓库变更 切换源

git remote set-url origin [url]

git clone 'url'

git add .

git commit -m 'fixed something'

git remote -v 

没有源作者项目url 创建: git remote add upstream 'url'

在本地目录下 git fetch upstream

将最新版本同步到本地目录 git merge upstream/master  

 切换到master分支 git checkout master 

fork 冲突问题

git mergetool

git clone指定分支

git clone url -b <分支名字>

.gitignore只能忽略那些原来没有被track的文件,如果某些文件已经被纳入了版本管理中,则修改.gitignore是无效的

 git rm -r --cached .

更新分支  git fetch

列出分支   git branch

列出所有分支   git branch -a

删除分支  git branch -d <branchName> 

罗列服务端所有的分支 git fetch -p

项目运用:

step1 : git clone <项目地址>

step2 : 切换到项目的目录,默认分支为(master)

step3 : 一般master分支是线上稳定的分支,所以需要创建一个开发版的分支,例如: develop分支

step4 : 通过coding或者GitHub 创建一个分支,例如: 我们在线上创建了 develop 分支或者别的分支,以下我们以develop为例

step5 : 通过本地命令行来查看线上所有的分支,运行命令: git branch -a

step6 : 若没有发现我们新创的分支 develop ,需要运行命令 : git fetch 来更新分支列表

step7 : 再次运行git branch -a,发现develop 分支后,我们需要切换到 develop 分支,运行命令 : git checkout develop

step8 : 我们发现本地分支变成了 develop 分支, 通过运行 git pull 将线上的代码同步到本地

step9 : 现在就可以在develop分支上面进行开发,再完成某个功能之后,我们需要将本地代码同步到线上,运行命令: git add . 

step10 : 再运行命令: git commit -m "代码变更的一些说明"

step11 : 再运行命令: git push 成功之后就同步到线上版本了

step12 : 现在develop分支 需要合并到 master,我们需要切换到master分支, 运行命令: git checkout master 有可能别人在master分支上提交了一些东西,所以需要先运行: git pull 将线上的版本同步到本地,成功之后 ,再运行命令: git checkout develop切换到 develop分支,再运行命令: git rebase master 将master分支合并到develop,检查冲突,合并成功后,确保能运行后,运行命令 : git push

step13 : 再切换到master 运行命令: git merge develop 再运行 git push就好了

OK!