12

I have two folders—A and B—in my file directory that link up to the same Git repository.

I created a file in folder A called index.html. I then create a different file also called index.html in folder B. I then add index.html in folder B, commit, and push B's contents.

When I pull from folder A, Git claims that my files are "Already up-to-date." However both folders clearly have different index.html files. What is going on?

4
  • Update - deleting "index.html" from folder A afterwards does not help. The error "Already up-to-date." still arises when I pull in folder A.
    – David Faux
    Apr 25, 2012 at 20:06
  • Did you do git rm index.html in A?
    – new123456
    Apr 25, 2012 at 20:30
  • 1
    When you created index.html in Folder A, did you git add and git commit it, or just put it in the folder? Git doesn't care what's in the folder, only what it's been told to care about.
    – asfallows
    Apr 25, 2012 at 20:33
  • only related to the title, just check your local origin is using absolute path rather than relative, as i was in a symlink, and id added my self as remote... Nov 17, 2021 at 20:57

4 Answers 4

11

git pull's job is to fetch new commits and merge them into the current branch. If the current branch is not outdated compared to the one you pull from, pull will say Already up-to-date. even if you have local changes in your working directory. git pull is concerned with branches, not the working tree — it will comment on the working tree only if there are changes which interfere with the merge.

Your description is insufficient to explain why it's not objecting to the existing index.html, but you should not take Already up-to-date. as meaning git thinks you have no changes. Instead, use git status to obtain a summary.

In order to understand the state of your branches, git branch -v is useful (it shows the commit ID and relation to each branch's upstream branch), or gitk --all for a graphical view of all commits.

2

If I understand correctly the following script should reproduce your issue:

mkdir test
cd test
git init --bare test.git
git clone test.git a
git clone test.git b
echo a > a/index.html
echo b > b/index.html
cd b
git add index.html
git commit -m add
git push origin master
cd ../a
git pull

The last git pull prints:

remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From /home/cyrus/tmp/test/test
 * [new branch]      master     -> origin/master

And the content of index.html has been silently overwritten:

cyrus:~/tmp/test/a$ cat index.html
b
2
  • I don't know what version of git you're using, but that is obviously not safe behavior. What if I had something important in that overwritten index.html? On the last pull, my git says error: Untracked working tree file 'index.html' would be overwritten by merge.
    – jjlin
    Apr 26, 2012 at 4:00
  • git version 1.7.2.5. I never said that's a safe behavior. That message pops out in certain circumstances, but that's not the case (don't ask me why).
    – cYrus
    Apr 26, 2012 at 8:27
1

Remember one thing about git - it tracks content, not files.

Internally, all of the content the repository keeps, is a blob somewhere. What you consider to be a file, git considers to be a name pointing to a blob. What you consider to be two files with the same content, git considers to be two names linked to the same blob. So, since none of the blobs have changed, then the repository has not changed.

You're expecting git to work like your filesystem does (or maybe like most other version control systems do) - git is actually more space-efficient in this regard. The book explains this concept pretty well - specifically, the Git Object Model.

0

Looks like you are used to SVN where different folders (or even files, don't know) can be checkouts of different revisions.

This is not possible with git. Independently of the folder you are in a commit or a checkout (which is also the final step of a successful pull) act on all work files independently of the folder you are currently in.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .