我对git相对较新(来自svn)。
我执行以下步骤,主要是我在分支上编辑文件,执行存储,然后尝试将存储应用于主服务器(没有此文件)。:
user1:~/gittest$ ls
user1:~/gittest$ git init
Initialized empty Git repository in /home/user1/gittest/.git/
user1:~/gittest$ touch file1
user1:~/gittest$ git add file1
user1:~/gittest$ git commit -m "committing file1"
[master (root-commit) 7c29335] committing file1
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 file1
user1:~/gittest$ git checkout -b br1
Switched to a new branch 'br1'
user1:~/gittest$ touch file2
user1:~/gittest$ git add file2
user1:~/gittest$ git commit -m "committing file2"
[br1 b565401] committing file2
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 file2
user1:~/gittest$ echo "updated.." >> file2
user1:~/gittest$ git add file2
user1:~/gittest$ git stash
Saved working directory and index state WIP on br1: b565401 committing file2
HEAD is now at b565401 committing file2
user1:~/gittest$ git checkout master
Switched to branch 'master'
user1:~/gittest$ git stash pop
CONFLICT (modify/delete): file2 deleted in Updated upstream and modified in Stashed changes. Version Stashed changes of file2 left in tree.
user1:~/gittest$ git status
On branch master
Unmerged paths:
(use "git reset HEAD <file>..." to unstage)
(use "git add/rm <file>..." as appropriate to mark resolution)
deleted by us: file2
no changes added to commit (use "git add" and/or "git commit -a")
我的问题是为什么git会打印“我们删除”的消息,因为file2从未在master上创建过,因此从未删除过。
这是一个误导性的信息,还是我错过了关于git工作方式的一些信息。
答案 0 :(得分:1)
这只是一个误导性的信息;它是说删除了,但它从来就不存在,它没有区分之前存在的文件和现在被删除的文件,或者根本不存在的文件,如果你从“分支视角”看它。
file2
实际上是git存储库中的已知文件,因此在某种意义上它会在您签出master
时被删除。