2

I have files and folder (let's say settings.py and migrations/ folder) in my local filesystem that I don't want to track anymore. (They were tracked the first time, when I push my code on my remote server).

What I want : when I run a git pull on my remote server I update only the code tracked and let the settings.py andmigrations/ folder off the update.

So here's what I did :

(on my local filesystem)

First,

I added `myapp/settings.py` and `migrations/` in my .gitignore file.

Then,

git rm --cached myapp/settings.py
git rm --cached -r migrations/
git add .
git commit -m "remove settings.py and migrations folder"
git push -u origin master

The settings.py file and migrations folder were successfully removed from my GitHub repo.

My problem : when I run a git pull on my remote server (when there is modifications of settings.py and migrations folder), it is as if settings.py and migrations folder were still tracked. :

  $me@server git pull origin master
        ....
        error: Your local changes to the following files would be overwritten by merge:
            migrations/0001_initial.py
            myapp/settings.py
        Please, commit your changes or stash them before you can merge.
        Aborting

I would like the server to ignore these changes since I have them untracked from my repo.

Another helpful information ? : I don't know if that can I help but I do not want to commit changes from my remote to the GitHub repo, I just want to pull the changes from the GitHub repo (because the 'right' code must come from my local repo, except for settings.py and migrations folder which are different on remote). So, if that can be of any help, here is the result of git status on my remote server:

# On branch master
# Your branch is behind 'origin/master' by 5 commits, and can be fast-forwarded.
#
# 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:    catalog/migrations/0004_auto_20150115_1214.pyc
#   deleted:    catalog/migrations/0005_auto_20150116_0855.py
#   deleted:    catalog/migrations/0005_auto_20150116_0855.pyc
#   deleted:    catalog/migrations/0006_auto_20150119_1153.py
#   modified:   myapp/settings.py
#

Thanks a lot for the help!

Reveclair
  • 2,399
  • 7
  • 37
  • 59
  • possible duplicate of [Completely remove file from all Git repository commit history](http://stackoverflow.com/questions/307828/completely-remove-file-from-all-git-repository-commit-history) – Tonio Jan 29 '15 at 17:03

2 Answers2

0

I did not test the solution offered by the duplicate (but would definetely testing if the same problem reappears) because I have already done something that solves my question : I simply removed the remote repository and did again a git clone on remote and now, this remote repository behaves as expected.

Reveclair
  • 2,399
  • 7
  • 37
  • 59
-1

After you remove the files, you do a git add . This might add the files again unless you have added them to your gitignore file.

Hammerstad
  • 148
  • 2
  • 8
  • Thank you for your answer. The files I want to untracked were put in my .gitignore file, but this did not resolve my problem. But you're right, that's worth noticing, I'll update my question. – Reveclair Jan 29 '15 at 12:54
  • 1
    Once a file is being tracked, `git rm` won't untrack it, it will just record the removal as a change. `.gitignore` stops files from being added to the list of files that are tracked, but it won't stop a file that's already being tracked from continuing to be tracked. – Tonio Jan 29 '15 at 17:02