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.

1
  • 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. Commented Dec 24, 2021 at 2:06

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.