【问题标题】:How to merge file in git [duplicate]如何在git中合并文件[重复]
【发布时间】:2021-02-07 09:42:39
【问题描述】:

当我尝试提交时,出现以下错误。

我搜索了,但是我是初学者,我想了解一下状态。

 $ git commit -m "test"
U       api/src/app.module.ts
U       api/src/entities/user.entity.ts
U       api/src/main.ts
error: Committing is not possible because you have unmerged files.
hint: Fix them up in the work tree, and then use 'git add/rm <file>'
hint: as appropriate to mark resolution and make a commit.
fatal: Exiting because of an unresolved conflict.

如何合并它们?

我在 vscode 中保留了这两个变化。

还有其他命令吗?

如果有人有意见,请告诉我。

谢谢

git 状态如下。

$ git status
On branch event-api
Your branch and 'origin/develop' have diverged,
and have 11 and 20 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)

You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)

Changes to be committed:
        modified:   ../../ormconfig.js
        modified:   ../../package.json
        new file:   ../config/CustomNamingStrategy.ts
        modified:   ../entities/child.entity.ts
        new file:   ../entities/condition.entity.ts
        new file:   ../entities/defecation.entity.ts
        new file:   ../entities/food.entity.ts
        modified:   ../entities/height.entity.ts
        new file:   ../entities/notice.entity.ts
        new file:   ../entities/sleep.entity.ts
        new file:   ../entities/temperature.entity.ts
        modified:   ../entities/weight.entity.ts
        modified:   event.controller.ts
        modified:   event.service.ts
        new file:   ../health/dto/health-info-filter.ts
        new file:   ../health/health-item.enum.ts
        new file:   ../health/health.controller.ts
        new file:   ../health/health.module.ts
        new file:   ../health/health.service.ts
        new file:   ../notices/dto/notice.dto.ts
        new file:   ../notices/notice.service.spec.ts
        new file:   ../notices/notice.service.ts
        new file:   ../notices/notices.controller.spec.ts
        new file:   ../notices/notices.controller.ts
        new file:   ../notices/notices.module.ts
        modified:   ../repositories/child.repository.ts
        new file:   ../repositories/notices.repository.ts
        new file:   ../shared/http-exception.filter.ts
        new file:   ../shared/timeout.interceptor.ts
        modified:   ../../yarn.lock

Unmerged paths:
  (use "git add <file>..." to mark resolution)
        both modified:   ../app.module.ts
        both modified:   ../entities/user.entity.ts
        both modified:   ../main.ts

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   ../entities/child.entity.ts
        modified:   ../entities/condition.entity.ts
        modified:   ../entities/defecation.entity.ts
        modified:   ../entities/event.entity.ts
        modified:   ../entities/food.entity.ts
        modified:   ../entities/height.entity.ts
        modified:   ../entities/sleep.entity.ts
        modified:   ../entities/temperature.entity.ts
        modified:   ../entities/weight.entity.ts
        modified:   dto/event.dto.ts
        modified:   ../health/dto/health-info-filter.ts
        modified:   ../health/health-item.enum.ts
        modified:   ../health/health.controller.ts
        modified:   ../health/health.module.ts
        modified:   ../health/health.service.ts
        modified:   ../migrations/develop/1592202356067-create-user.ts
        modified:   ../repositories/child.repository.ts
        modified:   ../shared/http-exception.filter.ts
        modified:   ../shared/timeout.interceptor.ts
        modified:   ../user/dto/user-search.request.ts
        modified:   ../user/user.module.ts

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        ../../../.vscode/
        ../../.env
        ../entities/attendance.entity.ts

【问题讨论】:

  • 错误说明了要做什么“在工作树中修复它们,然后根据需要使用'git add/rm '来标记分辨率并进行提交。” - 工作树是你的文件系统。
  • 这能回答你的问题吗? How to resolve merge conflicts in Git?

标签: git github


【解决方案1】:

如果您打开 git status 的此部分中的每个文件,您将看到由于无法确定自动分辨率而由 Git 自动添加的标记行(即已修改的相同行):

Unmerged paths:
  (use "git add <file>..." to mark resolution)
        both modified:   ../app.module.ts
        both modified:   ../entities/user.entity.ts
        both modified:   ../main.ts

冲突标记

对于每个文件,您需要做的是手动编辑内容并自行删除过时的更改,包括冲突标记本身。只有这样您才能发出git add,然后最终运行您的git commit -m "test" 命令。

<<<<<<< HEAD
Baz.
=======
Bar.
>>>>>>> main

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-04
    • 1970-01-01
    • 2013-01-02
    • 1970-01-01
    • 2016-05-05
    • 2011-02-11
    • 2013-11-21
    • 2021-12-19
    相关资源
    最近更新 更多