I am having a confusing issue with git
On main/development
I have a file that has the most up-to-date changes of UsersTable.tsx
On my working branch chore/add-linting
I am a few commits ahead, but I want to pull the latest code of UsersTable.tsx
from main/development
.
I performed:
$ git pull origin main/development
# oh no, I have a couple merge conflicts
# I want this file to be whatever is exactly on `main/development`
$ git checkout main/development path/to/UsersTable.tsx
Updated 1 path from f59fed63
However, the file is NOT what is main/development
! The version that it checked out for me is still behind main/development
and has old code.
What is going on here? I did git fetch
and the git pull
.
CodePudding user response:
Whenever you need to restore one file, you might consider using the command git restore
instead of the old and confusing git checkout
.
In your case:
git fetch
git restore -SW -s origin/main/development -- path/to/UsersTable.tsx
That way, you don't pull, meaning do not merge origin/main/development
to chore/add-linting
, so you don't have any merge conflict to manager.
You just restore one file content from a version of another branch.