git 命令学习
last-update: 2016年10月27日
1. git stash
简短描述
当你正在进行项目中某一部分的工作,但是里面的东西处于一个比较杂乱的状态,但是却想要切换到其他分支。问题是,你不想提交进行了一半的工作,否则以后你无法回到这个工作点。解决这个问题的办法就是 git stash 命令。
"储藏"(Stashing)可以获取你工作目录的中间状态——也就是你修改过的被追踪的文件和暂存的变更——并将它保存到一个未完结变更的堆栈中,随时可以重新应用。
简单恢复状态
使用 git stash apply 命令恢复保存的变更,假如出现冲突的情况,可以用 git mergetool 来解决。
2. 冲突合并
from https://github.com/jquery/jquery/readme.md#Handling merge conflicts
如果在合并时遇到合并冲突,假如不是手动编辑冲突的文件,可以使用 git mergetool 功能。 虽然默认工具xxdiff看起来很丑/旧,但它是相当有用。
下面是一些可以使用的命令:
Ctrl + Alt + M- 尽可能自动合并b- 调到下个冲突的地方s- 改变冲突行的顺序u- 撤销合并鼠标左键- 标记一个块为结果鼠标中键- 标记一行为结果Ctrl + S- 保存Ctrl + Q- 退出
3. 逆序打印 git 记录
git log --reverse -p
为学习而生。
4. revert 单个文件
Assuming the hash of the commit you want is c5f567:
git checkout c5f567 file1/to/restore file2/to/restore
The git checkout man page gives more information.
If you want to revert to the commit before c5f567, append ~1 (works with any number):
git checkout c5f567~1 file1/to/restore file2/to/restore
As a side note, I've always been uncomfortable with this command because it's used for both ordinary things (changing between branches) and unusual, destructive things (discarding changes in the working directory).

浙公网安备 33010602011771号