1

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.

Zac
  • 1,719
  • 3
  • 27
  • 48
  • You needed to use the name `origin/main/development` here, just as with `git restore`. But `git restore` is better *because* it is *less powerful:* it's easier to do the wrong thing with `git checkout` by mistake. – torek Dec 24 '21 at 02:06

1 Answers1

1

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250