Harriett Xing
Harriett Xing

Reputation: 49

git: File shows up as modified immediately after checkout from repo

jen.test@wswp0 MINGW64 /c/inetpub/wwwroot/2.0 (master)

$ git fetch


jen.test@wswp0 MINGW64 /c/inetpub/wwwroot/2.0 (master)

$ git checkout origin/master -- testFile.php


jen.test@wswp0 MINGW64 /c/inetpub/wwwroot/2.0 (master)

$ git status testFile.php

On branch master

Changes to be committed:

  (use "git reset HEAD <file>..." to unstage)

        modified:   testFile.php


jen.test@wswp0 MINGW64 /c/inetpub/wwwroot/2.0 (master)

$

This is what I was trying to do - I have made changes to several files including testFile.php from another computer. Those files are committed to the repo, and I executed a "git push origin master". I like to get the latest testFile.php from the repo, but not the other files.

Upvotes: 0

Views: 105

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 522752

I think there might be some potential confusion here about what the commands you executed are doing. When you did git fetch, you did update the tracking branch origin/master. But, you didn't actually update your local master branch, because you never merged or did a git pull. The command:

git checkout origin/master -- testFile.php

Actually updates your local working copy of testFile.php with a version from a different branch. It might seem confusing, but at the time you did this, your local master and the branch origin/master were not the same thing.

Then, git status reported that this file had been changed versus the HEAD of your local master branch.

Upvotes: 1

Related Questions