git学习笔记

git reset --hard origin/master //把自己的本地master分支和远程master分支保持一致
git revert HEAD //撤销最近一次提交
git revert HEAD~1 //撤销上上次的提交,注意:数字从0开始
git revert 0ffaacc //撤销0ffaacc这次提交

=======12-21=======

HEAD commit版本
Index staged版本

b、查看已经暂存起来的文件(staged)和上次提交时的快照之间(HEAD)的差异
git diff --cached
git diff --staged
显示的是下一次commit时会提交到HEAD的内容(不带-a情况下)

c、显示工作版本(Working tree)和HEAD的差别
git diff HEAD

d、直接将两个分支上最新的提交做diff
git diff topic master 或 git diff topic..master

e、输出自topic和master分别开发以来,master分支上的changed。
git diff topic...master
Changes that occurred on the master branch since when the topic branch was started off it
f、查看简单的diff结果,可以加上--stat参数
git diff --stat

g、查看当前目录和另外一个分支的差别
git diff test
显示当前目录和另一个叫'test'分支的差别
git diff HEAD -- ./lib
显示当前目录下的lib目录和上次提交之间的差别(更准确的说是在当前分支下)
git diff -- filename
只显示文件filename的差别

h、比较上次提交commit和上上次提交
git diff HEAD^ HEAD

i、比较两个历史版本之间的差异
git diff SHA1 SHA2

j、压栈当前工作区

$git stash
do some work
$git stash pop

git stash save "work in progress for foo feature"
’git stash list’ 打印Git栈信息便于区分版本号,
例如使用’git stash apply stash@{1}’就可以将你指定版本号为stash@{1}的工作取出来,
当你将所有的栈都应用回来的时候,可以使用’git stash clear’来将栈清空。

===========12-29============

git cherry-pick 6623be8 将其它分支中id为6623be8拿到当前分支上!
git reflog 查看所有能查看到的操作的记录(有些东西看不到的,但是它可以看到)
git reflog |grep rvc
git fetch 同步服务器代码
git config --global core.whitespace cr-at-eol 让git diff的时候忽略换行符的差异:
git diff test.txt只使用git diff 查看某一个文件
git diff HEAD -- ./test.txt
git diff test.txt master

原文地址:https://www.cnblogs.com/hellokitty2/p/8076532.html