0

我有两个分支。有一个文件,存在于两个分支中。自从两个分支分歧之前,它就没有改变过。当我将一个分支合并到另一个分支时,git 会删除该文件。我看不出它这样做的理由。考虑以下控制台日志,我在其中检查两个分支中是否存在该文件,然后尝试合并,并显示该文件现在已被删除。(我已经编辑了特定的细节,但事件的顺序保持不变,我向你保证,分阶段更改部分中列出的每个文件都是一个 .swift 文件,与有问题的已删除文件不同。)

$ git checkout develop
Switched to branch 'develop'
Your branch is up to date with 'origin/develop'.
$ ll PROJECT.xcworkspace/xcshareddata/swiftpm/Package.resolved 
-rw-r--r--  1 USER  USER  603 Apr 00 00:00 PROJECT.xcworkspace/xcshareddata/swiftpm/Package.resolved
$ git checkout feature/FEATURE
Switched to branch 'feature/FEATURE'
Your branch is up to date with 'origin/feature/FEATURE'.
$ git checkout develop
Switched to branch 'develop'
Your branch is up to date with 'origin/develop'.
$ git status
On branch develop
Your branch is up to date with 'origin/develop'.

nothing to commit, working tree clean
$ ll PROJECT.xcworkspace/xcshareddata/swiftpm/Package.resolved 
-rw-r--r--  1 USER  USER  603 Apr 00 00:00 PROJECT.xcworkspace/xcshareddata/swiftpm/Package.resolved
$ git checkout feature/FEATURE
Switched to branch 'feature/FEATURE'
Your branch is up to date with 'origin/feature/FEATURE'.
$ git status
On branch feature/FEATURE
Your branch is up to date with 'origin/feature/FEATURE'.

nothing to commit, working tree clean
$ ll PROJECT.xcworkspace/xcshareddata/swiftpm/Package.resolved 
-rw-r--r--  1 USER  USER  603 Apr 00 00:00 PROJECT.xcworkspace/xcshareddata/swiftpm/Package.resolved
$ git merge develop
Auto-merging PROJECT.xcodeproj/project.pbxproj
CONFLICT (content): Merge conflict in PROJECT.xcodeproj/project.pbxproj
Automatic merge failed; fix conflicts and then commit the result.
$ git status
On branch feature/FEATURE
Your branch is up to date with 'origin/feature/FEATURE'.

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

Changes to be committed:

    new file:   PROJECT/PATH/SOME_SWIFT_FILES.swift
    modified:   PROJECT/PATH/SOME_OTHER_SWIFT_FILES.swift

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

    both modified:   PROJECT.xcodeproj/project.pbxproj

Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    deleted:    PROJECT.xcworkspace/xcshareddata/swiftpm/Package.resolved

$ ll PROJECT.xcworkspace/xcshareddata/swiftpm/Package.resolved 
ls: PROJECT.xcworkspace/xcshareddata/swiftpm/Package.resolved: No such file or directory
$

为什么要这样做?认为 git 可能会自发地自行引入错误的更改,这是非常令人不安的。

4

0 回答 0