newby issue:我的提交在哪里消失了

时间:2013-08-02 01:33:29

标签: git

我对git非常新,刚开始玩它。 这就是我所做的:

john@john:~/workspace/git-test/tmp$ git log --pretty=oneline

7d6bebed1d7bcfd916dd930303b7e95c974ad354 xThis will be amended
2c32b4519c8c06e6e6ae381a67d6824a33a512ce another emty file
cd34e9e0c40f18984f66e58bd1650c98f8c3aedf Merge branch 'master' of /home/john/workspace/git-test/../tmp
408020f5e0ffda578e8690a487c80f3c22ea2804 Empty file added
4b80be932603083d9712aa4329812d045d22eafa added emty file
7ab109a5fe405dcb9f52424a8b27790b51ff43bf Testing .gitignore?
92ba23c892102e8162b700a43548567cefe7183a Initial setup

我尝试切换到之前的提交:

john@john:~/workspace/git-test/tmp$ git checkout -b issue01 408020f

Switched to a new branch 'issue01'

并查看日志:

john@john:~/workspace/git-test/tmp$ git log --pretty=oneline

408020f5e0ffda578e8690a487c80f3c22ea2804 Empty file added
7ab109a5fe405dcb9f52424a8b27790b51ff43bf Testing .gitignore?
92ba23c892102e8162b700a43548567cefe7183a Initial setup

问题:

此提交在哪里4b80be932603083d9712aa4329812d045d22eafa added emty file? 我很确定我做错了什么,只是不知道在哪里检查它......

更新

john@john:~/workspace/git-test/tmp$ git log --pretty=oneline --graph
* 408020f5e0ffda578e8690a487c80f3c22ea2804 Empty file added
* 7ab109a5fe405dcb9f52424a8b27790b51ff43bf Testing .gitignore?
* 92ba23c892102e8162b700a43548567cefe7183a Initial setup

john@john:~/workspace/git-test/tmp$ git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 4 commits.
john@john:~/workspace/git-test/tmp$ git log --pretty=oneline --graph
* 7d6bebed1d7bcfd916dd930303b7e95c974ad354 xThis will be amended
* 2c32b4519c8c06e6e6ae381a67d6824a33a512ce another emty file
*   cd34e9e0c40f18984f66e58bd1650c98f8c3aedf Merge branch 'master' of /home/john/workspace/git-t
|\  
| * 4b80be932603083d9712aa4329812d045d22eafa added emty file
* | 408020f5e0ffda578e8690a487c80f3c22ea2804 Empty file added
|/  
* 7ab109a5fe405dcb9f52424a8b27790b51ff43bf Testing .gitignore?
* 92ba23c892102e8162b700a43548567cefe7183a Initial setup

2 个答案:

答案 0 :(得分:4)

git log <commit>显示可从<commit>到达的历史记录。如果您查看历史记录,您会发现4b80be9 added emty file不是408020f的祖先,因此它不会显示在git log 408020f的输出中。您只能在第一个命令的输出中看到它,因为--oneline按时间顺序排列提交,即使历史记录不是线性的。

查看有关branching and merging的git-scm文档。他们很棒并且很好地解释了这些概念。

答案 1 :(得分:1)

$git checkout -b issue01 408020f

从任何提交“408020f”克隆存储库:

HEAD指向您当前的分支(或当前提交),因此git reset --hard HEAD所做的就是丢弃任何未提交的更改。