Git merge:冲突,我不知道该如何解决

时间:2020-03-10 18:02:28

标签: python django git

我在Git上有一个Django项目

我对Git不太满意

我已经确定,提交并推送了我的feature / 22分支

我已经提交(在git add之后)并推送了我的主人

所以我的两个分支都是最新的

现在,我想将我的母版与我的feature / 22本地合并,但是我有冲突

即使在提交之后,“ Unmerge path”中也有2个文件:

Unmerged paths:
  (use "git add <file>..." to mark resolution)
        both modified:   unblind/migrations/__pycache__/0002_auto_20200124_0904.cpython-37.pyc
        both modified:   unblind/migrations/__pycache__/0003_auto_20200124_1007.cpython-37.pyc

如果我使用推荐的命令git add怎么办?

为什么这2个文件未包含在先前的git add中。命令?

编辑:

$ git merge feature/22
warning: Cannot merge binary files: unblind/migrations/__pycache__/0003_auto_20200124_1007.cpython-37.pyc (HEAD vs. feature/22)
warning: Cannot merge binary files: unblind/migrations/__pycache__/0002_auto_20200124_0904.cpython-37.pyc (HEAD vs. feature/22)
Auto-merging unblind/migrations/__pycache__/0003_auto_20200124_1007.cpython-37.pyc
CONFLICT (content): Merge conflict in unblind/migrations/__pycache__/0003_auto_20200124_1007.cpython-37.pyc
Auto-merging unblind/migrations/__pycache__/0002_auto_20200124_0904.cpython-37.pyc
CONFLICT (content): Merge conflict in unblind/migrations/__pycache__/0002_auto_20200124_0904.cpython-37.pyc
Removing randomization/templates/randomization/_randomisation_edit.html
Automatic merge failed; fix conflicts and then commit the result.

EDIT2:

我暂时解决了合并问题:

  • git checkout功能/ 22
  • rm(合并master / feature / 22时在CONFLICT中提到的所有文件
  • git commit -m“删除* .pyc”
  • git checkout master
  • git merge feature / 22
  • git push原始主机

BUT .pyc仍会被跟踪,并且在master上运行django项目后,如果我执行git status:

$ git status
On branch master
Your branch is up to date with 'origin/master'.

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:   export/migrations/__pycache__/__init__.cpython-37.pyc
        modified:   parameters/migrations/__pycache__/0003_auto_20200128_1337.cpython-37.pyc
        modified:   parameters/migrations/__pycache__/0004_auto_20200129_1206.cpython-37.pyc
        modified:   parameters/migrations/__pycache__/0005_auto_20200305_0810.cpython-37.pyc
        modified:   parameters/migrations/__pycache__/0006_auto_20200305_1238.cpython-37.pyc
        modified:   parameters/migrations/__pycache__/0007_auto_20200305_1242.cpython-37.pyc
        modified:   parameters/migrations/__pycache__/0008_auto_20200305_1428.cpython-37.pyc
        modified:   pharmacy/migrations/__pycache__/0001_initial.cpython-37.pyc
        modified:   pharmacy/migrations/__pycache__/0002_auto_20200129_1206.cpython-37.pyc
        modified:   pharmacy/migrations/__pycache__/0003_auto_20200129_1434.cpython-37.pyc
        modified:   pharmacy/migrations/__pycache__/0004_auto_20200210_1750.cpython-37.pyc
        modified:   pharmacy/migrations/__pycache__/0005_historicalstock_stock.cpython-37.pyc
        modified:   pharmacy/migrations/__pycache__/0006_auto_20200218_1344.cpython-37.pyc
        modified:   pharmacy/migrations/__pycache__/0007_auto_20200218_1359.cpython-37.pyc
        modified:   pharmacy/migrations/__pycache__/0008_auto_20200218_1403.cpython-37.pyc
        modified:   pharmacy/migrations/__pycache__/0009_auto_20200218_1410.cpython-37.pyc
        modified:   pharmacy/migrations/__pycache__/0010_auto_20200302_1059.cpython-37.pyc
        modified:   pharmacy/migrations/__pycache__/__init__.cpython-37.pyc
        modified:   randomization/migrations/__pycache__/0008_auto_20200302_1059.cpython-37.pyc

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        unblind/migrations/__pycache__/

no changes added to commit (use "git add" and/or "git commit -a")

3 个答案:

答案 0 :(得分:2)

您可以忽略项目中的任何/__pycache__/文件夹。

  1. 如果您还没有.gitignore,则可以在项目文件夹中直接创建一个:project/.gitignore
  2. */__pycache__/*放入.gitignore

答案 1 :(得分:0)

将pycache文件存储在git存储库中从来不是一个好主意。 该文件由py_compile module在每个版本中自动生成。

您可以添加此文件来解决合并冲突,但是我建议在项目的根目录使用.gitignore。

在您的项目中添加一个不错的.gitignore

答案 2 :(得分:0)

使用

删除那些缓存的文件
rm -rf <path_of_filename>

尝试不要用

推送代码
 git add.

继续练习以开始添加

.gitignore

在开始任何项目之前,向其中添加缓存和已编译的文件。