Pregunta

I have Git setup on my machine, and it's been doing something strange.

I'll start from scratch.

[nighthawk]$ cd ~
[nighthawk]$ rm -rf ./www
[nighthawk]$ ls
Maildir  logs
[nighthawk]$ 

Now I will clone the repository.

[nighthawk]$ git clone https://key:@github.com/user/repo.git ./www
Cloning into ./www...
remote: Counting objects: 260, done.
remote: Compressing objects: 100% (195/195), done.
remote: Total 260 (delta 82), reused 217 (delta 47)
Receiving objects: 100% (260/260), 7.41 MiB | 4.88 MiB/s, done.
Resolving deltas: 100% (82/82), done.
[nighthawk]$ cd www
[nighthawk]$ git status
# On branch master
nothing to commit (working directory clean)
[nighthawk]$ 

Now I can see it. It's there.

I'm going to make a change to the README file, and then pull those changes onto this machine.

This is very strange:

[nighthawk]$ 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:   README.md
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   public/README.md
no changes added to commit (use "git add" and/or "git commit -a")
[nighthawk]$ 

It seems the .git folder is updated, but the checked out directory directory is not. Also: the file public/README.md file does not exist in the repository. It exists in the ~/www (the root of the repository).

I've tried everything I could think of for setting file permissions, but I'm still baffled. How can I get Git to update my checkout?

Thanks in advance!

PS: This machine's git version is 1.7.2.5.

Update:

This is how I edited the README.md file in the root of the repository:

Modifying:

On a separate computer:
Squid:repo Jonn$ vim README.md
Squid:repo Jonn$ git add -A
Squid:repo Jonn$ git commit -m "Edited README again."
[master e2a4d36] Edited README again.
 1 file changed, 1 insertion(+), 1 deletion(-)
Squid:repo Jonn$ git push origin
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 386 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/user/repo.git
   882a196..e2a4d36  master -> master
Squid:repo Jonn$ 

Pulling:

Then a webhook to the www/public/deploy.php page called the following command:

echo shell_exec('git --git-dir=/home/jonn/www/.git pull origin');

Output:

Updating 882a196..e2a4d36
Fast-forward
 README.md |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
¿Fue útil?

Solución

It seems the .git folder is updated, but the checked out directory directory is not.
Also: the file public/README.md file does not exist in the repository. It exists in the ~/www (the root of the repository).

Considering where you clone that repo (in ~/www), it seems normal that your status shows public/README.md as "untracked".

One simple way to maintain consistency in your git repo content would be to edit (or add) your .gitignore in ~/www and add:

/public/

In order to ignore the public folder entirely.

The OP Jonn adds:

For some reason the changes I made to /README.md were pulled into the subdirectory /public/README.md (which didn't exist before).

I advise to use the --work-tree parameter in order to be sure of the worktree location updated by a git pull:

echo shell_exec('git --git-dir=/home/jonn/www/.git --work-tree=/home/jonn/www pull origin');

With recent version of Git (1.8.5), that could be specified as:

echo shell_exec('git -C /home/jonn/www pull origin');
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top