git学习笔记
2015-08-14 09:21
253 查看
在Git中,用HEAD表示当前版本。上一个版本就是HEAD^,上上一个版本就是HEAD^^,当然往上100个版本写100个^比较容易数不过来,所以写成HEAD~100。
git reset:set the current branch head (HEAD) to commit
git rebase命令的i参数表示互动(interactive),这时git会打开一个互动界面,进行下一步操作。
你可以通过运行 git show [commit_hash] 查看提交之后的改变或者运行git merge [commit_hash] 来恢复到之前的提交。
总结自己的Git常用命令
Git回滚的常用手法
git revert和git reset的区别
修改最后一次commit的记录
[code]git commit -m "a wrong commit" #修改一些数据 git commit --amend
[code]git revert HEAD~1 #回滚到倒数第二次commit
revert和reset的区别
git revert是用一次新的commit来回滚之前的commitgit reset:set the current branch head (HEAD) to commit
[code]git revert HEAD~1 # resolve conflicts git revert --continue
[code]git reset --soft HEAD~1 #Does not touch the index file or the working tree at all git reset --mixed(default ) HEAD~1 #Resets the index but not the working tree git reset --hard HEAD~1 #Resets the index and working tree
[code]git checkout <branch> #switch branch rm -f hello.c git checkout master hello.c #restore hello.c from the index
查看文件中的每一行的作者、最新的变更提交和提交时间
[code]git blame [file_name]
git reflog则列出了head曾经指向过的一系列commit。要明白它们只存在于你本机中;而不是你的版本仓库的一部分,也不包含在push和merge操作中。
[code]git reflog
rebase压缩多个Commit
分支开发完成后,很可能有一堆commit,但是合并到主干的时候,往往希望只有一个(或最多两三个)commit,这样不仅清晰,也容易管理。[code]git rebase -i master
git rebase命令的i参数表示互动(interactive),这时git会打开一个互动界面,进行下一步操作。
Stash未提交的更改
你正在修改某个bug或者某个特性,又突然被要求展示你的工作。而你现在所做的工作还不足以提交,这个阶段你还无法进行展示(不能回到更改之前)。在这种情况下, git stash可以帮助你。stash在本质上会取走所有的变更并存储它们为以备将来使用。[code]git stash git stash list #希望检查stash列表 git stash apply #解除stash并且恢复未提交的变更
检查丢失的提交
尽管 reflog 是唯一检查丢失提交的方式。但它不是适应用于大型的仓库。那就是 fsck(文件系统检测)命令登场的时候了。[code]git fsck --lost-found
你可以通过运行 git show [commit_hash] 查看提交之后的改变或者运行git merge [commit_hash] 来恢复到之前的提交。
Refer:
10 个迅速提升你 Git 水平的提示总结自己的Git常用命令
Git回滚的常用手法
git revert和git reset的区别
相关文章推荐
- UINavigationBar的系统渲染方式
- Scope Is the Enemy of Success
- 树堆
- asp.net的Request.ServerVariables参数说明
- POJ 2251 Dungeon Master(BFS+数据读取)
- iframe中将子页面A中的某个变量值传到子页面B中
- 如何让tomcat在同一个DOS窗口启动
- “Software Architect” Has Only Lowercase a’s; Deal with It
- JavaScript 属性介绍
- Java基础:继承和多态
- Entity Framework教程(第二版)
- ReverseMap
- Linux的命令及全称
- mysql的XA与innodb_support_xa
- hdu 2896 病毒侵袭 AC自动机
- rowspan和colspan用法详解
- 看清贬值的真实情况再惊恐
- inet_pton、inet_ntop
- 用快速排序实现”小哼买书“
- tr 与 td