Git merge: conflict I don't know how to resolve

Viewed 6039

I have a Django project on Git

I am not very confortable with Git

I have juste finalized, commit and push my feature/22 branch

I have commit (after git add .) and push my master

So my two branchs are up to date

Now, I would like to merge my master with my feature/22 locally but I have an conflict

Even after commit, I have 2 files in "Unmerge paths" :

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

What if I use the recommanded command git add?

Why these 2 files were not contained in the previous git add . command?

EDIT:

$ 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:

I have resolved temporarly my merge problem:

  • git checkout feature/22
  • rm (all files that were mentionned in CONFLICT when merge master / feature/22
  • git commit -m "delete *.pyc"
  • git checkout master
  • git merge feature/22
  • git push origin master

BUT .pyc are still tracked and after running my django project on master, if I do 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 Answers

You can ignore any /__pycache__/ folder from your project.

  1. If you don't already have a .gitignore, you can make one right inside of your project folder: project/.gitignore.
  2. Put */__pycache__/* in the .gitignore

remove those cached file with

rm -rf <path_of_filename>

try not to push your code with

 git add.

keep practice to start adding

.gitignore

before starting of any project, and add cache,compiled files into it.

This is never a good idea to store your pycache files in your git repository. This files are automatically generated by the py_compile module on each build.

You can add this files to resolve the merge conflict, but I recommend to use a .gitignore at root of your project.

Here is a good .gitignore to add in your project.

Related