jpw
jpw

Reputation: 19257

my local git repo has "not staged" deleted files, remote is file, how do I pull the missing files?

I've read about git clean and git reset but I don't think they do what I need. I tried git pull but it didn't fix the issue (git pull results in: Already up-to-date.)

My remote repo at github is fine.

I just copied all my rails projects from my old PC to my new Mac which also has a working rails dev environment.

Everything else moved fine, but somehow, a lot of my db/migration files are missing locally. (No idea why... nothing else is missing.)

When I cd into the directory and run git status I see the same thing:

# On branch master
# Changes not staged for commit:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   deleted:    db/migrate/20110330064532_init_user_guids.rb
#   deleted:    db/migrate/20110330065055_init_master_report_key.rb
#   deleted:    db/migrate/20110331001956_create_recurly_accts.rb

Anyway, I am looking for the command that will pull all the missing (not staged + deleted) files from the remote (origin) to local, without removing any of the untracked files locally such as my sqlite database.

Or maybe a git command that restores them from my local git repo, since the deletions are "unstaged"?

(I should add that I have no other unstaged changes... just those missing files I need to replace.)

Upvotes: 3

Views: 4607

Answers (3)

Ben Jackson
Ben Jackson

Reputation: 93900

All that status is telling you is that the files are in the repository but not in the working copy. The repository is also right there on the machine with you. git status thinks you did rm db/migrate/... as a change that you might want to commit (just like if you edited a file). To undo those changes you can use git checkout db/migrate/... to get unmodified (in this case, not deleted) copies from your local repository. If you have no other pending changes you can do that en mass with git reset --hard.

You should not need to get the objects that represent these files from your remote repo unless by some dark magic those objects are also missing as well. In that case a simple git fetch will bring over the objects to your local repo and you can recover your working copy as described above.

Upvotes: 1

Lily Ballard
Lily Ballard

Reputation: 185841

If the only changes are the missing files, you can just use git reset --hard HEAD, and that will restore everything back to the pristine state. However, it will not delete any untracked files (you need git clean for that). So this should be safe to run, as it will restore your missing files, but leave your untracked database alone.

Upvotes: 6

vcsjones
vcsjones

Reputation: 141703

Try:

git checkout db/migrate/20110330064532_init_user_guids.rb

etc.

Upvotes: 3

Related Questions