tags:

views:

219

answers:

5

I do:

$ git commit .
$ git push
error: Entry 'file.php' not uptodate. Cannot merge.

Then I do

$ git pull
Already up-to-date.

What do I do? I just want to get the latest version from the remote copy, and overwrite anything on my local copy.

Edit: I tried everything. I deleted my local repo, and

$ git clone ssh://[email protected]/directory
...
Checking out files: 100%, done.

$ git status
On branch master
nothing to commit (working directory clean)

All looks good, right? Pull just in case.

$ git pull
Already up-to-date.

I make a one line change in a file to see if I can push it.

$ git commit .
[master 1e18af1] Rando change
1 files changed, 2 insertions(+), 0 deletions(-)

$ git push
Counting objects: 13, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (7/7), 646 bytes, done.
Total 7 (delta 3), reused 0 (delta 0)
From /directory
d6d61aa..1e18af1  master     -> origin/master
error: Entry 'someotherfile.php' not uptodate. Cannot merge.
Updating b8f9a54..1e18af1
To  ssh://[email protected]/directory
d6d61aa..1e18af1  master -> master

I have no idea what's going on! How can I commit/pull again normally? Thanks very much!

+1  A: 

Try to do a git status and check if you've got any non commited changes to 'file.php'. You need to commit all the changes on the same files, or git could change your non-commited file.

Try to make another commit after the pull, and then try to pull again, review any possible merge and push the data.

If you want just to overwrite your local copy, checkout the file file.php (git checkout HEAD^ file.php to checked version previous to last one) to a previous version, and then pull from the repository.

Khelben
I did your suggestions (edit above), but nothing works. Any ideas? Also the git checkout HEAD^ -- file.php doesn't seem to be a valid command -- what comes after the -- (can't take a file parameter).
Jasie
Sorry, I'm correcting the command...
Khelben
+2  A: 

Try doing a git checkout file.php then git push again.

Update:

  • git pull tells the branch is up-to-date?
  • git status doesn't show any unmerged file?
  • git commit works?

If you answered yes to all above, and your git push keeps failing even after a clean copy of the remote repository (read git clone), it's very likely the remote repository has an index problem.

jweyrich
Tried this. Just says > Everything up-to-date after I push.
Jasie
What does `git diff` show you? Conflicts should have been pointed by `git commit`, I guess. Also, `git status` would show them as unmerged.
jweyrich
git diff doesn't show any output. I suppose that means there's no diff?
Jasie
+1  A: 

I would cut and paste my file.php locally out of the working folder. To your desktop lets say.

Then do a pull, then git should fetch the lastest file.php from the server. Then just paste in your copy of file.php and overwrite the pulled one or open up both versions and just paste in your changes.

I hope that does the trick.

I wish the pull would work. Instead, it says > Already up-to-date.
Jasie
A: 

Are you sure you didn't have already a file.php with a different case? (File.php or file.PHP...), as in this answer?

  • one already commit
  • one on your working directory, with a different case.
VonC
I'm sure of it.
Jasie
+1  A: 

This is just a hunch, but was your remote a bare repo or a working directory? If it was a working directory rather than a bare repo, the file.php file on the remote had uncommitted changes. Your git push command was trying to advance the HEAD at the remote which was causing conflicts due to the uncommitted changes.

This is why you usually git pull to update a working directory, and use git push on bare repos. FYI, to setup a bare repo for use as something similar to a central CVS/SVN/etc repo, do the following on the remote:

$ mkdir my-git-repo
$ cd my-git-repo
$ git init --bare

Then in your local repo:

$ cd my-git-repo.git
$ git remote add origin user@host:/path/to/my-git-repo/
$ git config branch.master.remote origin
$ git config branch.master.merge refs/heads/master
$ git push origin master

Now you have a bare repo to push/pull into/from that contains your master branch. You can repeat the last three local steps with any additional local branches you want to put on the remote. Cloning is the same as before and you don't need to use git config as remotes are set automatically and remote merging refs are set when you use tracking branches.

Hope that helps.

jcordasc