Git 命令
git 的一些琐碎操作。
配置
git-config
- 获取并设置存储库或全局选项。
# 修改 commit 编辑器
$ git config --global core.editor "vim"
共享和更新项目
git-pull
- 从另一个存储库或本地分支获取并与之集成。
- 等价于
git fetch; git merge FETCH_HEAD
。
# 等价于 git fetch; git rebase
$ git pull --rebase
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 4 (delta 2), reused 4 (delta 2), pack-reused 0
Unpacking objects: 100% (4/4), done.
From github.com:vflong/vflong.github.io
19bf7ef..2af5153 master -> origin/master
First, rewinding head to replay your work on top of it...
Applying: :pencil2: git rebase
# 常用命令
$ git pull --rebase upstream master
打补丁
git-rebase
- 在另一个分支基础上重新应用提交。
# 解决冲突
$ git diff
$ git add <filename>
$ git rebase --continue
# 撤销 git rebase
$ git rebase --abort
git-revert
- 还原提交。
$ git revert 52170dbf
[zh-trans-1094 d0f16881] Revert "del extra space"
1 file changed, 9 insertions(+), 9 deletions(-)
$ git commit -m 'revert to 52170dbf'
On branch zh-trans-1094
nothing to commit, working tree clean
# 强制覆盖远程分支,慎用
$ git push -f origin zh-trans-1094
Counting objects: 8, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (7/7), done.
Writing objects: 100% (8/8), 720 bytes | 360.00 KiB/s, done.
Total 8 (delta 5), reused 0 (delta 0)
remote: Resolving deltas: 100% (5/5), completed with 5 local objects.
To github.com:vflong/istio.io.git
+ 61403f8d...d0f16881 zh-trans-1094 -> zh-trans-1094 (forced update)
分支与合并
git-stash
- 将更改存储在脏的工作目录中
# 切换分支前执行 stash
$ git stash
$ git checkout master
$ git checkout develop
# 回到原开发分支后继续开发
$ git stash pop