Revert file from Git remote branch

You can revert just that single file from other remote branch without touching anything else. Option 1: Restore file from remote branch (recommended)
git fetch origin 
git checkout origin/[remote_branch] -- file_path_in_GIT
This will: Take the version of the file from remote origin/[remote_branch] Overwrite your local copy Leave you on your current branch Then commit it:
git commit -m "Revert file from other branch"
Option 2: If your local branch is already tracking the remote branch You can shorten it to:
git checkout [remote_branch] -- file_path_in_GIT
(Still followed by a commit.) Option 3: Using modern git restore (Git ≥ 2.23)
git fetch origin 
git restore --source=origin/[remote_branch] -- file_path_in_GIT
Then commit:
git commit -m " Revert file from other branch"
Verify before committing (optional but smart)
git diff
⚠️ Notes This does not switch branches This does not affect other files Any uncommitted changes to that file will be overwritten
Total page views:

Comments

Popular posts from this blog

Useful aliases

Start all Docker containers