github学习
1、配置git
用户名:git config --global user.name "xxx"
邮箱: git config -global user.email "xxx"
2、创建版本库
把文件夹变成git可以管理的仓库 git init
把文件添加到仓库 git add xxx
把文件提交到仓库并且提交说明 git commit -m “the illustrate”
3、查看日志
查看版本修改日志(查看提交的) git log --pretty=oneline(后面的参数表示一行显示)
git reset --hard xxxx(版本号) 版本回退
git reflog(查看历史命令)
git diff HEAD -- xxxx(文件名) 查看最新版本的工作区和暂存区区别
4、撤销修改
git checkout -- file 可以丢弃工作区的修改
加入文件没有加入到暂存区,那么回到与版本库一样的状态,若已经加入到暂存区,则回到与暂存区一样的状态。
git status 查看状态,可以看到一些命令。
git reset HEAD file 将暂存区的修改撤销,返回到工作区。
5、删除文件
在工作区删除文件以后,有两种选择
the first choice
git rm file
git commit -m "illustrate” 在git中删除文件
the second choice
git checkout -- file 在版本库中将文件返还回来。
6、添加远程仓库
首先将本地仓库与远程仓库相连
git remote add origin https://github.com/Awille/xxx.git
其中的origin代表远程仓库 是可以更改名字的。
接下来将本地仓库的内容同步到远程仓库
git push -u origin master
其中-u参数是第一次把master分支加进去才要 的 以后可以简化
git push origin master
7、从远程库克隆
git clone https://github.com/Awille/xxx.git
8、创建与合并分支
git branch 查看分支
git branch <name> 创建分支
git checkout <name> 切换到分支
git checkout -d <name> 创建+切换到该分支
git merge <name> 合并某分支到当前分支
git branch -d <name> 删除分支
9、解决分支冲突问题
git log --graph --pretty=oneline --abbrev-commit 查看分支
10、分支管理策略
git merge --no-ff -m "xxx" <name>
普通合并模式 可以看出曾经合并的历史信息
11、bug分支
git stash 保存工作现场
git stash list 查看stash
恢复工作区:
git stash apply + git stash drop
或者 git stash pop
可以多次stash git stash apply stash@{stash标号}
12、多人协作模式
(1)git push origin <mybranchname>
(2)if have conflict :git pull
(3)if pull failed: $ git branch --set-upstream-to origin/dev
(4)sovle confict and commit.
git remote -v :查看远程库信息。
git checkout -b <branchname> origin/branchname
git pull origin master --allow-unrelated-histories