Git是一个快速的版本控制工具。 --查看历史记录 --追踪更改 --管理共享数据库 --防止无意的重写覆盖
1. 安装Git -- http://git-scm.com/dowmloads
2. 配置:
$ git config --global user.name NinaYoung
$ git config --global user.email 18612498868@163.com
a. 生成ssh key (私钥 公钥)
$ ssh-keygen -t rsa -C "youremail@email.com"
3. 创建本地数据库(locale repository):
$ mkdir Project
$ cd Project
$ git init
4. GitHub: Fork
关联个人仓库和公共仓库的
5. clone 远程分支
$ git clone 远程分支
6. 用command修改文件
echo “Hi Nina” > mylife.txt
7. 添加远程分支
$ git remote add [name] [address]
8. 常用方法:
$ git checkout -b [patchName] upstream/develop
$ git status
$ git add . / 文件
$ git commit -m "comments" / --amend
$ git push origin patch (-f)
$ git fetch [仓库] branch 获取某个仓库和分支上的 code
$ git rebase
9. 获取别人分支上的code
a,$ git checkout -b [patchName] othersRpo/patchName (获取之前先fetch)
b, $ git pull --rebase othersRpo/patchName
10. cherry-pick 从本地一个分支上copy commit到当前分支
$ git cherry-pick [commit code]
11.
如果新的分支没有commit –m, 直接commit –amend,push –f的话会push到前面一个commit上面,这时要:
Git rebase upstream/develop (这样会分出一个和上个commit 一样的commit)
Git reset –mixed [第二个commit的码] (这样就会到了提交之前的状态 正常提交就可以了)
12. 合并两个PR
git log -3
git rebase -i HEAD~2
13. 可能出现提交人错误要恢复到提交之前的状态 再提交
gitk 查看提交人
git log -3个
git reset --mixed 倒数第二个PR的commit号
gitk 查看提交人 (查看当前分支的 在本地的 所有code)
git add .
git commit –m “”
git push –f