git pull doesn’t actually restore my missing files from remote

git pull corresponds to the sequence of a git fetch and then git merge. So if you delete the files from your local repository, doing a git pull will not restore them.

In order to restore them you need to checkout that files from the remote repository using:

git checkout <branch name> -- <path/to/file>

<branch name> can be local or remote.

Example: Using remote repository

  1. Remote upstream name: origin
  2. Remote branch: feature/xpto
  3. Local branch: feature/xpto
  4. File missing on local branch: example.js
  5. Recover the file to the local branch from remote branch: git checkout origin/feature/xpto -- example.js
  6. Now you have example.js back on your local branch

Example 2: Rollback a commit

  1. git log
  2. Current commit hash 7bb2154cf23b68feb0a0bbbd95446f2cd8bf3a44
  3. Want to rollback to this commit hash dbc04c23b2c6f2dd7bc9b5ef4aef22611a57c3ad
    • git checkout dbc04c23b2c6f2dd7bc9b5ef4aef22611a57c3ad
  4. Only want to recover the file example.js from the above commit hash
    • git checkout dbc04c23b2c6f2dd7bc9b5ef4aef22611a57c3ad -- example.js

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)