I have been working on a branch. I committed and pushed it up to the remote repository. Now some files on that branch are missing. Hopefully they are still available on the remote branch, so I tried to do git pull
:
git pull origin feature/my_branch
However, git said all is synchronized with remote:
* branch feature/my_branch -> FETCH_HEAD Already up-to-date.
How can that be up to date? I cannot find my missing files locally, and my project didn't compile because of those missing files. Again, I can see those files in the commit history of the remote branch on bitbucket.
The short answer is simple: no, the remote-tracking branch remains unaffected.
The git pull command first runs a git fetch command to check for changes. The fetch operation returns the metadata for our commits . Then, the git pull command retrieves all the changes we have made to our remote repository and changes our local files.
For obvious safety reasons, Git will never simply overwrite your changes.
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.
git checkout origin/feature/xpto -- example.js
example.js
back on your local branchgit log
7bb2154cf23b68feb0a0bbbd95446f2cd8bf3a44
dbc04c23b2c6f2dd7bc9b5ef4aef22611a57c3ad
git checkout dbc04c23b2c6f2dd7bc9b5ef4aef22611a57c3ad
example.js
from the above commit hash git checkout dbc04c23b2c6f2dd7bc9b5ef4aef22611a57c3ad -- example.js
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With