Inspection
Bring a file from another branch or commit
4 min read
Sometimes you need just one file from somewhere else: the configuration that's right in main,
the file a colleague fixed in feature/relatorios or the version from an old tag. Bring file
from another branch or commit… replaces the file in your working directory with that version,
without switching branches and without touching the other files.
Before bringing it, the window shows what changes in the file and warns you if anything of yours would be replaced. Ctrl+Z puts the file back as it was.
- File menu (right-click a file in the changes panel or in a commit's list): Bring from another branch or commit…
- Revision comparison, Files tab: right-click a file › Bring the version from <revision>…, which comes with the revision already chosen.
- Palette (Ctrl+P): "Bring file from another branch or commit…" ("Replaces the file in the working directory with the chosen version (Ctrl+Z undoes it)"). From the palette, you type the file path in the window.
- Right-click
config/app.jsonand choose Bring from another branch or commit…. - In the Bring config/app.json from… window ("Pick the branch, tag or commit the file
version comes from."), choose
main. Any branch, tag, SHA or git expression works, such asHEAD~3. - The Bring file from main window explains: "The version of the file in main replaces the one in your working directory. Branches don't change."
- Check the fields:
- File: the path. To change it, type another one; the suggestions, under Files in the revision, come from the chosen revision.
- From: the revision. Change… picks another one.
- Read the preview: "From your current file (−) to the version in main (+):". If the file doesn't exist on disk today, the preview shows the whole incoming version.
- If you want the file to go straight to staging, check Also stage it (like a git checkout of a file).
- Click Bring file. When something of yours is going to be replaced, the button is called Replace and bring. While it runs, "Bringing config/app.json…" appears; at the end, the notice "config/app.json came from main".
| Option | What it does | Default |
|---|---|---|
| Also stage it (like a git checkout of a file) | Besides the disk, writes the version to staging. | Unchecked; your choice is remembered |
First, the preview (read only):
git cat-file -t <sha>:<file> # does the file exist in the revision?
git status --porcelain -z -- <file> # are there local changes?
git diff -R <sha> -- <file> # from the disk to the revision's version
Then, when you confirm:
git restore --source=<sha> --worktree [--staged] -- <file>
Without the staging option, only the working directory changes. With it, the result is equivalent
to git checkout <sha> -- <file>. Branches, HEAD and the other files don't change.
Before bringing the file, Versora keeps a copy of it, including what was staged. Ctrl+Z undoes Bring <file> and puts the file back as it was: the uncommitted changes and an untracked file with the same name also come back. See Undo and redo.
- "This file has uncommitted changes, which will be replaced. They're kept: Ctrl+Z brings them back.": your work on the file will be swapped for the revision's version.
- "There's an untracked file with this name, which will be replaced. It's kept: Ctrl+Z brings it back.": there's a file with that name on disk that git doesn't know about.
- "<file> doesn't exist in <revision>: there's nothing to bring.": the revision doesn't have the file. Bringing it would delete yours, and that isn't "bringing"; to delete, use the normal discard.
- "The file is already the same as in <revision>.": there's no difference.
- ""<file>" is a folder in this revision; pick a file.": the path points to a folder.
- "Binary file: the preview only shows that it changes.": the preview doesn't show the content of binaries.
- "The preview was cut short; the whole file is brought.": very large diffs appear only partly in the preview, but the file comes in full.
- "Type the file path (suggestions come from the chosen revision).": appears when the window was opened from the palette, without a file.
Tip
To take a file back to a version from its own history, the shortest path is Restore file from this version… in the file history.
This feature has no preference of its own and no company policy key.