tags:

views:

27

answers:

1

Hi there,

I've got some trouble with a git setup I wanted to use in our company.

I set up a git "server" with the main code repository on a ubuntu hardy machine with git 1.5.4.3. I'm new to git and set up this repository step by step with tutorial.

git init
git add .
git commit -m "initial commit"

Then I set up a client (Win XP) git install with version 1.7.3.1.msysgit.0 (official git for windows) and cloned that repository over ssh.

git clone <IP>:/var/git/<repo> <target>
<made some file changes>
git status ob my client then says:

$ git status
# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   searchfunc_admin.php
#
no changes added to commit (use "git add" and/or "git commit -a")

then I do a commit -a which gives:

[master 9404d01] + searchfunc_admin.php DB Verb. Prüfung modifiziert
 1 files changed, 3 insertions(+), 3 deletions(-)

an then I push to the repository on the server:

$ git push origin master
<user>@<IP>'s password:
Counting objects: 5, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 385 bytes, done.
Total 3 (delta 2), reused 0 (delta 0)
To 192.168.1.26:/var/git/farocmsafs
   5267756..9404d01  master -> master

On the ubuntu machine, I cd to the master repo and check what happened:

git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   searchfunc_admin.php
#

If I check the DIFF, it shows the changes but they are handled as old code that should be updated with the original code (which is the real old code)

git diff HEAD
diff --git a/searchfunc_admin.php b/searchfunc_admin.php
index 4e15696..17ca17a 100755
--- a/searchfunc_admin.php
+++ b/searchfunc_admin.php
@@ -9,11 +9,11 @@ require_once("additional/functions.php");
 // INITS
 //**********
 // Connect to database
-if(!$mylocal || !$myafs)
+if($DB_CONNECTION != TRUE)
 {
-       if(!sqldb_connect())
+       if(($sql_return = sqldb_connect()) != TRUE)
        {
-               echo "Cant connect to database";
+               echo "Cant connect to database: ".$sql_return;
                die(1);
        }
 }

If I execute git commit he ask me for the message, commits, but no changes of the new pushed code are applied.

I've found out that my only chance to apply the new changes is a git reset --hard with the remote commit ID. But that way I have to apply all changes to the code by hand.

I don't use other branches, only "master" and don't use git commit with any other parameters than "-a" so I don't have any clue where the origin of that error is.

From what I've read so far, this could be a detached HEAD problem, but I don't know why the head is detached. If I made local changes on the ubuntu machine, all goes well. I can commit and see the changes on my remote machine after a fetch or pull. But I'm unable to apply remote changes other that with reset --hard.

Hope Someone can help me with this.

Best Regards, Sebastian

+1  A: 

Don't push to a non-bare repository. It will update the head but not the working tree, leading to weird behavior when you look at it later. You can fix it by doing a git reset --hard to update the working tree on the server to the current head.

There are two ways to fix this:

  1. Initialize a new repository on the server with git init --bare
  2. Clear out the working tree on the server and move the entire contents of the .git subdir to the top-level. You should probably rename the repository so it ends with .git, as that is customary for bare repositories.
Jonathan