JWDev
JWDev

Reputation: 856

Git: Ignored a file, now says there's unmerged files and can't pull

Previously, I had WordPress' wp-config.php committed; since then, I've now ignored this file in .gitignore, which is fine.

Unfortunately - now when pulling to live, it provides this error:

M   .htaccess
U   wp-config.php

Pull is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>'
as appropriate to mark resolution, or use 'git commit -a'.

Before this issue happened, I had an issue with pulling where it said I had uncommitted changes with these files - so I let it overwrite them, then I uploaded the actual files manually via FTP, which caused this new error.

I want to keep the files in their current state on the live server, but get around this error now and in the future.

What is the process of being able to pull the latest changes with this?

Upvotes: 0

Views: 311

Answers (1)

Mark Adelsberger
Mark Adelsberger

Reputation: 45749

UPDATE - I'm adding an answer to a question posed in comments, and clarifying a related point


First let's clear up a little confusion: This error has nothing to do with putting the file in .gitignore. In fact, since the file is present in the index, .gitignore has no effect whatsoever on the file.

Before this issue happened, I had an issue with pulling where it said I had uncommitted changes with these files - so I let it overwrite them

You may need to be more clear about what commands you issued and what output you saw, because this is where your trouble is coming from.

When you say you "let it overwrite them", what does that mean? git resists overwriting local changes (especially uncommitted changes)...

I'm guessing what really happened is that git tried to merge changes from the remote repo into your local changes for those files, but had merge conflicts on wp-config.php.

And most likely it's still in a merging state, which you'll have to resolve before you can move on. If you say git status it will likely tell you that you're merging, with some changes "to be committed" (likely including the .htaccess file) and some "unmerged paths" (likely including the .php file).

If you have the .php file looking the way you want it in the work tree, then you can say git add wp-config.php and then git commit which should cause the merge to complete. (More generally, you have to get the file looking how you want it in the index, and do this in a way that tells git the conflict is resolved; and then you can commit to get out of the merging state.)

Now in comments you ask about whether this will put the file "back" into git. And that comes down to what it means to "have the .php file looking the way you want it".

If you never want git to provide the .php file (even during a fresh clone), then you need to remove it from the index and subsequent commit.

You could (at least temporarily) remove the file from the working tree and then do a git add (as noted above). Or, if you don't want to affect your working tree version, you can

git rm --cached wp-config.php

directly making the index look "how you want it". At this point it becomes possible for your .gitignore entry to help you avoid accidentally reintroducing the file.

If what you mean is that the file should be there, but only a default version should be in the repo (not taking any changes that might be made in the working tree), git won't do that. You'll have to get where you're going a different way. For example you could put the file in the repo as wp-config.php.default and ignore the wp-config.php path. After cloning the repo you would then copy the default file, and any local changes would be made only to the ignored copy.

Upvotes: 2

Related Questions