skip to content
Alvin Lucillo

Restore a file based on another branch version

/ 1 min read

You can get another version of the file in your branch from another branch with git restore.

Below shows that the current branch is feature1 and notes has version 4

$ git branch --show-current
feature1
$ cat notes
version 4

notes from another branch, main, was restored, meaning that version was pulled into the current branch.

$ git restore --source main -- notes

Now notes has version 3.

$ cat notes
version 3
$ git status
On branch feature1
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified: notes

no changes added to commit (use "git add" and/or "git commit -a")