我已经学会了如何合并来自this link的其他分支的特定文件。但是,此帖子不适用于合并已删除的文件。我已经创建了一个git存储库来模拟这种情况,所以你可以试试这个。这是一个例子,
$git clone https://github.com/gtchoi/SO_question.git
$git branch --track test origin/test
$git checkout test
$git checkout master -- .
$git status
On branch test
Your branch is up-to-date with 'origin/test'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: a.html
$ls
a.html b.html index.html
正如您和我预期的那样(请参阅the repository),与当前分支(测试)相比,a.html必须添加到工作树中,因此git设法从主分支获取a.html,但是b.html仍在工作树中。我想从工作树中删除b.html,因为b.html已从master分支中删除。如何合并其他分支中的已删除文件?
答案 0 :(得分:0)
问题似乎是b独立于主分支添加到test
分支
如果您真的只想让test
与master
相同,请使用例如
$ git reset --soft master
$ git status
On branch test
Your branch and 'origin/test' have diverged,
and have 3 and 1 different commit each, respectively.
(use "git pull" to merge the remote branch into yours)
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
deleted: a.html
new file: b.html
$ git commit -am 'made identical to master branch'
[test 56ab8cb] made identical to master branch
2 files changed, 1 insertion(+), 1 deletion(-)
delete mode 100644 a.html
create mode 100644 b.html