Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
是';吉特rm';对';由我们删除';是否应该删除该文件? 让我们考虑一下这个简短的Git场景: (master)>echo 1 > a.txt (master)>git add a.txt (master)>git commit -m "Commit 0" (master)>git checkout -b b (b)>git rm a.txt (b)>git commit -m "Deleted a.txt" (b)>git checkout master (master)>echo 2 > a.txt (master)>git commit -am "Modified a.txt" (master)>git checkout b (b)>git merge master CONFLICT (modify/delete): a.txt deleted in HEAD and modified in master. Version master of a.txt left in tree. Automatic merge failed; fix conflicts and then commit the result._Git_Github_Git Merge - Fatal编程技术网

是';吉特rm';对';由我们删除';是否应该删除该文件? 让我们考虑一下这个简短的Git场景: (master)>echo 1 > a.txt (master)>git add a.txt (master)>git commit -m "Commit 0" (master)>git checkout -b b (b)>git rm a.txt (b)>git commit -m "Deleted a.txt" (b)>git checkout master (master)>echo 2 > a.txt (master)>git commit -am "Modified a.txt" (master)>git checkout b (b)>git merge master CONFLICT (modify/delete): a.txt deleted in HEAD and modified in master. Version master of a.txt left in tree. Automatic merge failed; fix conflicts and then commit the result.

是';吉特rm';对';由我们删除';是否应该删除该文件? 让我们考虑一下这个简短的Git场景: (master)>echo 1 > a.txt (master)>git add a.txt (master)>git commit -m "Commit 0" (master)>git checkout -b b (b)>git rm a.txt (b)>git commit -m "Deleted a.txt" (b)>git checkout master (master)>echo 2 > a.txt (master)>git commit -am "Modified a.txt" (master)>git checkout b (b)>git merge master CONFLICT (modify/delete): a.txt deleted in HEAD and modified in master. Version master of a.txt left in tree. Automatic merge failed; fix conflicts and then commit the result.,git,github,git-merge,Git,Github,Git Merge,此时的状态是: (b|MERGING)>git status On branch b You have unmerged paths. (fix conflicts and run "git commit") (use "git merge --abort" to abort the merge) Unmerged paths: (use "git add/rm <file>..." as appropriate to mark resolution)

此时的状态是:

(b|MERGING)>git status
On branch b
You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)

Unmerged paths:
  (use "git add/rm <file>..." as appropriate to mark resolution)

        deleted by us:   a.txt

(b|合并)>git状态
关于b分支
您有未合并的路径。
(修复冲突并运行“git提交”)
(使用“git merge--abort”中止合并)
未合并路径:
(酌情使用“git add/rm…”标记分辨率)
已被我们删除:a.txt
我的解决方法是
git rm a.txt
。这会给我我所需要的,但是,这是解决这个问题的方法吗?换句话说,有没有一种更具表现力的方式(比如git merge accept_delete)来处理这个问题


git checkout a.txt——我们的
不起作用,因为我们的端不存在a.txt)

git rm
是我首选的方法。Git本身并不关心如何产生结果;它只关心您将正确的分辨率放入索引中。让您的工作树也反映您的索引通常是好的,但Git并不关心这一点:这只是为了您自己的理智

在此特定状态下,文件
a.txt
出现在索引槽1和3中,而不是索引槽2中。插槽1中的
a.txt
版本是从合并库中获取的副本。插槽3中的版本是从
master
的尖端获取的副本。此
master
版本的
a.txt
也会出现在工作树中

使用:

rm a.txt
git add a.txt
将首先从工作树中删除
a.txt
,然后再从索引槽1和3中删除它,在索引中完全不保留
a.txt
,这是您想要的状态。但更简单的是:

git rm a.txt
将从工作树以及索引槽1和3中删除
a.txt
,产生完全相同的结果

Git只关心索引中的内容。slot zero条目中的文件您可以使用
git ls Files--stage
查看它们,不过如果您有很多文件,那么在下一次提交时打印的文本量会非常大。插槽1、2和/或3中的文件处于“冲突”状态。在git commit或任何其他进行提交的操作可以继续之前,需要清除这些内容


无论是
git add
还是
git rm
都可以删除冲突状态条目,所以这两种方法都可以,但是我觉得
git add
一个不存在的文件感觉很奇怪。在这种情况下,你必须先删除它,然后感觉很奇怪。

我也更喜欢
git rm
,因为我知道自己在做什么。值得注意的是,
git merge strategy option=ours
的存在,它总是从您的分支接收更改。但如果我理解得很好,在b上合并时,它会删除master的任何更改。您可以检查是否对其他策略感到好奇(尽管它们看起来非常具体)。