为什么“git checkout master”没有将文件内容恢复为以前的状态?

时间:2012-08-29 07:01:10

标签: git git-branch

比如说,如果文件foo已经提交,则其内容为

just a simple line

现在git checkout -b issue57已完成创建分支并切换到它(例如,issue57分支将持续2天进行开发),并且现在将一行footer added添加到文件中,然后是git commit -a -m "add a footer to the file"

所以现在文件foo有内容

just a simple line
footer added

当需要“热修复”或“快速修复”时,我认为应该使用命令git checkout master,现在文件foo的内容应该只返回一个线。但是当我more foo时,文件有两行,为什么会这样?

1 个答案:

答案 0 :(得分:4)

对我来说效果很好:

$ more foo
just a simple line
$ echo "footer added" >> foo
$ git checkout -b issue57
M   foo
Switched to a new branch 'issue57'
$ git commit -a -m "add a footer to the file"
[issue57 c397054] add a footer to the file
1 file changed, 1 insertion(+)
$ more foo
just a simple line
footer added
$ git checkout master
$ more foo
just a simple line

也许您已在git checkout -b issue57之前提交了文件?