配置
/etc/gitconfig
全局配置文件
~/.gitconfig
用户 git 配置文件
配置 ssh 代理
# in ~/.ssh/config
Host github.com
User git
ProxyCommand nc -x localhost:1080 %h %p
配置 http/https 代理
git config --global http.proxy "http://127.0.0.1:8080"
git config --global https.proxy "http://127.0.0.1:8080"
配置邮箱与名字
git config --global user.name "John Doe"
git config --global user.email johndoe@example.com
配置remote
# 查看 remote
git remote -v
# 查看某个 remote 的详细信息
git remote show origin
# 添加 remote
git remote add origin git@github.com:michaelliao/learngit.git
# push 到对应的 remote 的 master 分支
git push -u origin master
# 删除某个 remote
git remote rm origin
分支
git merge
git rebase
git merge --no-ff
git merge --squash
git log --graph --pretty=oneline --abbrev-commit
git status
git rebase
合并分支
git rebase --interactive HEAD~[7]
撤销已经 push 了的 commit
git reflog
git reset --hard <版本号>
git push origin <分支名> --force
合并多个 commit
git reflog
git rebase -i <想合并的版本号之前一个版本号>
在互动模式的 rebase 中,将想合并的 commit 前的 pick 改为 squash
pick 382a2a5 add database settings
pick cd82f29 add cat 1
squash 1de2076 add cat 2
squash ca40fc9 add 2 cats
pick 2bab3e7 add dog 1
squash 27f6ed6 add dog 2
使用 squash 来将commit 压缩
上面的例子中,27f6ed6 将和 2bab3e7 合并,ca40fc9、1de2076 将和 cd82f29 合并
之后使用 `git push –force” 命令强制推到 remote 即可