设置
git config --global user.name "mattmonkey" git config --global user.email "mattmonkey@sina.com"列出
git config --list git config --global --list git config --local --list颜色
git config --global color.branch auto git config --global color.diff auto git config --global color.interactive auto git config --global color.status auto git config --global color.ui auto别名
git config --global alias.st status git config --global alias.ci commit git config --global alias.co checkout git config --global alias.br branch git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --"其他
git config format.pretty oneline
qgit: | 查看历史 |
---|---|
gitk: | git默认的gui管理工具 |
lighttpd: | web server |
git instaweb: | web based 管理工具 |
生成SSH Key
cd ~/.ssh ssh-keygen -t rsa -C "xxxxxx@xxx.com"添加Key到 github ssh
cat id_rsa.pub | xsel -b测试有效性
ssh -T git@github.com
生成SSH Key
** 主要不要和默认的ssh文件重复了**
key 加入到ssh-agent ssh-add ~/.ssh/id2_rsa
配置~/.ssh/config, t
# Default git Host github.com HostName github.com User git IdentityFile ~/.ssh/id_rsa # riptide git (riptide766@mail.com) Host github-riptide.com HostName github.com User git IdentityFile ~/.ssh/id2_rsa
配置git仓库
>>> git remote -v
origin git@github.com:riptide766/ubuntu-notes.git (fetch)
origin git@github.com:riptide766/ubuntu-notes.git (push)
>>> git remote rm origin
>>> git remote add origin git@github-riptide:riptide766/ubuntu-notes.git
>>> git pull origin master
git commit --amend --reset-author
库已经存在,切换到gh-pages分支
git clone git@github.com:mattmonkey/CtrlCtrl ctrlctrl
git checkout gh-pages
新建gh-pages分支
查看文件
git show HEAD:chrome/content/ctrlctrl.js
比较某个版本
列出简要差别
>>> git diff HEAD --stat >>> git diff HEAD~2 --stat
比较修改的部分
当前文件 和 上个版本 之间的差异
>>> git diff HEAD -- test当前文件 和 暂存区域快照 之间的差异
>>> git diff已经暂存 起来的文件和 上次提交 时的快照之间的差异.
>>> git diff --staged
diff的结果就是补丁。 使用apply命令打补丁
>>> git diff > /tmp/patch >>> git apply /tmp/patch
解除文件staged状态
>>> git reset HEAD file恢复文件
>>> git checkout -- python/indicator-demo.py >>> git checkout HEAD~2 -- python/indicator-demo.py
恢复之前的版本. 不包括Untracked files ,因为Untracked...
>>> git reset --hard恢复到之前的某个版本个,并 删除之间的记录
>>> git reset --hard er23另一种恢复版本的方法是 git revert . 不会删除提交记录。还会把恢复的版本作为一次提交。 :/first 用注释查找提交
>>> git revert :/firstgit checkout 可以切换的版本 ,但如果有冲突会报错提醒
>>> git checkout c2ca error: The following untracked working tree files would be overwritten by checkout: test Please move or remove them before you can switch branches.在旧版本里执行 git log 是查不到新版本的hash值的. 使用下面的命令回到最新版本
>>> git checkout master
一共有master,develop feature release fixbug五种分支。后面三种是临时的,使用完就清理掉。
用到的命令,以fixbug为例说明下.(和release比较像)
创建进入fixbug分支
>>> git checkout -b fixbug-0.1 master
回到master,合并分支,并打上tag。–no-ff在合并时会创建一个提交
>>> git checkout master
>>> git merge --no-ff fixbug-0.1
>>> git tag -a 0.1.1
合并到develop分支
>>> git checkout develop
>>> git merge --no-ff fixbug-0.1
删除分支
>>> git branch -d fixbug-0.1