Git合并错误是由Visual Studio引起的,在切换到主分支后发生。

huangapple go评论51阅读模式
英文:

Git merge error caused by visual studio after checking out to master branch

问题

我对Git还相对新手,仍然无法弄清最佳操作方法。

我使用这个流程,但似乎会导致错误。你能帮我修复吗?

->git clone [仓库名称]
->cd [仓库名称]
->git status
*在分支 master 上没有需要提交的更改
->git checkout -b "class-lib-move"
->start [项目名称].sln(在Visual Studio中打开代码)
做一些更改...
->git add .
->git commit -m "更改 ..."
->git checkout master
->git merge class-lib-move
*错误:您本地对以下文件的更改将被合并覆盖:
        .vs/VideoToText/v17/.suo
        /obj/Debug/net6.0/VideoToText.GeneratedMSBuildEditorConfig.editorconfig
        VideoToText/obj/Debug/net7.0/VideoToText.GeneratedMSBuildEditorConfig.editorconfig
        VideoToText/obj/Debug/net7.0/VideoToText.assets.cache
        VideoToText/obj/VideoToText.csproj.nuget.dgspec.json
        VideoToText/obj/VideoToText.csproj.nuget.g.props
        VideoToText/obj/project.assets.json
        VideoToText/obj/project.nuget.cache
在合并之前,请提交您的更改或将它们存储。
->git add .
->git commit -m "无用的提交"
->git merge class-lib-move
->git status

警告:无法合并二进制文件:.vs/VideoToText/v17/.suo(HEAD vs. class-lib-move)
自动合并 .vs/VideoToText/v17/.suo
冲突(内容):.vs/VideoToText/v17/.suo 中的合并冲突
自动合并 VideoToText/obj/VideoToText.csproj.nuget.dgspec.json
冲突(内容):VideoToText/obj/VideoToText.csproj.nuget.dgspec.json 中的合并冲突
自动合并 VideoToText/obj/project.assets.json
自动合并 VideoToText/obj/project.nuget.cache
冲突(内容):VideoToText/obj/project.nuget.cache 中的合并冲突
自动合并失败;解决冲突,然后提交结果。

我的操作就到此为止了。我只看到上传功能分支到远程、完全删除文件夹、再次克隆仓库,最后合并的选项。我是否漏掉了什么?

问题似乎是由Visual Studio引起的。在我切换到主分支时,它自动覆盖了一些文件...

英文:

Im pretty new to git and i still couldn't figure out the best approach, when it comes to flow of git.

Im using this flow, but it seems to cause errors. Could you fix it for me?

->git clone [repo name]
->cd [repo name]
->git status
*On branch master nothing to commit
->git checkout -b "class-lib-move"
->start [project name].sln (openning code in visual studio)
Making some changes...
->git add .
->git commit -m "changes ..."
->git checkout master
->git merge class-lib-move
*error: Your local changes to the following files would be overwritten by merge:
        .vs/VideoToText/v17/.suo
        /obj/Debug/net6.0/VideoToText.GeneratedMSBuildEditorConfig.editorconfig
        VideoToText/obj/Debug/net7.0/VideoToText.GeneratedMSBuildEditorConfig.editorconfig
        VideoToText/obj/Debug/net7.0/VideoToText.assets.cache
        VideoToText/obj/VideoToText.csproj.nuget.dgspec.json
        VideoToText/obj/VideoToText.csproj.nuget.g.props
        VideoToText/obj/project.assets.json
        VideoToText/obj/project.nuget.cache
Please commit your changes or stash them before you merge.
->git add .
->git commit -m "useless commit"
->git merge class-lib-move
->git status

warning: Cannot merge binary files: .vs/VideoToText/v17/.suo (HEAD vs. class-lib-move)
Auto-merging .vs/VideoToText/v17/.suo
CONFLICT (content): Merge conflict in .vs/VideoToText/v17/.suo
Auto-merging VideoToText/obj/VideoToText.csproj.nuget.dgspec.json
CONFLICT (content): Merge conflict in VideoToText/obj/VideoToText.csproj.nuget.dgspec.json
Auto-merging VideoToText/obj/project.assets.json
Auto-merging VideoToText/obj/project.nuget.cache
CONFLICT (content): Merge conflict in VideoToText/obj/project.nuget.cache
Automatic merge failed; fix conflicts and then commit the result.

And there goes my flow. I only see an option to upload the feature branch to remote, completely delete the folder,git clone repo again and and finaly merging it. Am i missing something out?

Problem seems to be caused by visual studio. In the moment im switching branch to master, it overwriting some files by itself...

答案1

得分: 1

问题在于您在仓库中保留了太多东西。例如,.vs 目录不需要受版本控制,生成的构建工件和文件,如 obj/Debug/ 也不应该受版本控制,以及(很可能)任何 *.cache 文件或目录中的内容。

在设置仓库时,您应该创建一个 .gitignore 文件,列出所有不是源代码的内容,这样 git add . 就不会将这些文件添加到仓库中。

事后修复是可能的,但会给那些已克隆仓库的人带来巨大的麻烦(基本上的指令是在将 the_unwanted_files 添加到 .gitignore 后执行 git rm --cached the_unwanted_files)。

我的另一种建议是:如果可以的话,从一个新的仓库开始。

英文:

The problem is that your keep too much stuff in the repository. For example, the .vs directory need not be under version control, nor should be the build artefacts and generated files such as obj/Debug/, nor (most likely) stuff in any *.cache file or directory.

When you set up the repository, you should have created a .gitignore file that listed everything that is not source code, so that git add . would not have added these files to the repository.

Fixing this after the fact is possible, but is going to cause a tremendous headache for anybody who has also cloned the repository (instructions are basically to git rm --cached the_unwanted_files after you have added the_unwanted_files to .gitignore).

My alternative recommendation is: if you can, start with a new repository.

huangapple
  • 本文由 发表于 2023年5月15日 14:49:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76251504.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定