在git pull中出现冲突错误:
user@os:/proects/path$ clear
user@os:/proects/path$ git pull origin frontend-4
Password for 'https://usrename@github.com':
From https://github.com/clientname/project
* branch frontend-4 -> FETCH_HEAD
error: Your local changes to the following files would be overwritten by merge:
package.json
public/js/app.js
public/mix-manifest.json
resources/js/components/common/Header.vue
resources/js/routes.js
Please commit your changes or stash them before you merge.
Aborting
user@os:/proects/path$ git stash在主目录上保存工作目录和索引状态WIP : e214191 Gigs图片
making git stash I got conflicts with npm autogenerated files :
user@os:/proects/path$ git pull origin frontend-4
Password for 'https://usrename@github.com':
From https://github.com/clientname/project
* branch frontend-4 -> FETCH_HEAD
Auto-merging resources/js/routes.js
Auto-merging resources/js/components/common/Header.vue
Auto-merging public/js/app.js
CONFLICT (content): Merge conflict in public/js/app.js
Auto-merging public/css/frontend.css
CONFLICT (content): Merge conflict in public/css/frontend.css
Auto-merging package.json
Automatic merge failed; fix conflicts and then commit the result.我试着先把它们去掉然后跑
npm run watch-poll下一步,但我得到了错误:
user@os:/proects/path$ rm public/js/app.js
user@os:/proects/path$ rm public/css/frontend.css
user@os:/proects/path$ git commit -m "ignore compiled asset"
U public/css/frontend.css
U public/js/app.js
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.如何修复呢?
我不需要像在.gitignore规则中设置这样的决策:
/public/js/*
/public/css/*因为我需要上传我的css/文件到服务器,因为我没有在服务器上安装npm。
发布于 2021-08-05 15:16:19
回答:找到阻止自动合并的行,然后执行rest
不提交或推送的主要问题是文件之间的冲突
Git可以通过自动合并功能独立处理大多数合并。如果两个单独的分支对文件中的同一行进行了编辑,或者在一个分支中删除了文件但在另一个分支中进行了编辑,则会发生冲突
有许多工具可以帮助解决合并冲突,例如:
<代码>H113git reset<代码>H214<代码>G215
#如何识别合并冲突
正如我们从前面的示例中所体验到的那样,Git将产生一些描述性输出,让我们知道冲突已经发生。我们可以通过运行git status命令获得更深入的了解
$ git status
On branch main
You have unmerged paths.
(fix conflicts and run "git commit")
(use "git merge --abort" to abort the merge)
Unmerged paths:
(use "git add <file>..." to mark resolution)
both modified: merge.txtmerge.text文件现在显示为已修改状态。让我们检查一下这个文件,看看修改了什么。
$ cat merge.txt
<<<<<<< HEAD
this is some content to mess with
content to append
=======
totally different content to merge later
>>>>>>> new_branch_to_merge_later在这里,我们使用cat命令输出merge.txt文件的内容。我们可以看到一些奇怪的新成员
把这些新的线条想象成“冲突分隔线”。=======线路是冲突的“中心”。中心和<<<<<<<标题行之间的所有内容都是存在于HEAD ref所指向的当前分支main中的内容。或者,中心和>>>>>>> new_branch_to_merge_later之间的所有内容都是存在于我们的合并分支中的内容。
#如何使用命令行解决合并冲突
解决合并冲突的最直接方法是编辑冲突的文件。在您喜欢的编辑器中打开merge.txt文件。对于我们的示例,让我们简单地删除所有冲突分隔符。然后,修改后的merge.txt内容应如下所示:
this is some content to mess with
content to append
totally different content to merge later编辑完文件后,使用git add merge.txt来存放新合并的内容。要完成合并,请通过执行以下命令创建新的提交:
git commit -m "merged and resolved the conflict in merge.txt"Git将看到冲突已经解决,并创建一个新的合并提交来完成合并。
帮助解决合并冲突的#Git命令
通用工具
git status状态命令在使用Git和合并时经常使用,它将帮助识别冲突的文件。
git log --merge将--merge参数传递给git log命令将生成一个日志,其中包含合并分支之间冲突的提交列表。
git diffdiff有助于发现存储库/文件的状态之间的差异。这对于预测和防止合并冲突很有用。
git无法启动合并时的工具
git checkout签出可用于撤消对文件的更改,或用于更改分支
git reset --mixed重置可用于撤消对工作目录和临时区域的更改。
在合并过程中出现git冲突时使用的工具
git merge --abort执行带有--abort选项的git merge将退出合并进程,并将分支返回到合并开始之前的状态。
git reset在合并冲突期间,可以使用Git重置将冲突的文件重置为已知的良好状态
https://stackoverflow.com/questions/68667881
复制相似问题