Setup and Config
Getting and Creating Projects
Basic Snapshotting
Branching and Merging
Sharing and Updating Projects
Inspection and Comparison
Patching
Debugging
External Systems
Server Admin
Guides
- gitattributes
- Command-line interface conventions
- Everyday Git
- Frequently Asked Questions (FAQ)
- Glossary
- Hooks
- gitignore
- gitmodules
- Revisions
- Submodules
- Tutorial
- Workflows
- All guides...
Administration
Plumbing Commands
- 2.51.1 no changes
-
2.51.0
2025-08-18
- 2.50.1 no changes
- 2.50.0 no changes
- 2.49.1 no changes
-
2.49.0
2025-03-14
- 2.43.1 → 2.48.2 no changes
-
2.43.0
2023-11-20
- 2.35.1 → 2.42.4 no changes
-
2.35.0
2022-01-24
- 2.30.1 → 2.34.8 no changes
-
2.30.0
2020-12-27
- 2.27.1 → 2.29.3 no changes
-
2.27.0
2020-06-01
- 2.25.1 → 2.26.3 no changes
-
2.25.0
2020-01-13
- 2.23.1 → 2.24.4 no changes
-
2.23.0
2019-08-16
ÜBERSICHT
git restore [<Optionen>] [--source=<Tree>] [--staged] [--worktree] [--] <Pfadspezifikation>… git restore [<Optionen>] [--source=<Tree>] [--staged] [--worktree] --pathspec-from-file=<Datei> [--pathspec-file-nul] git restore (-p|--patch) [<Optionen>] [--source=<Tree>] [--staged] [--worktree] [--] [<Pfadspezifikation>…]
BESCHREIBUNG
Stellt spezifizierte Pfade im Arbeitsbereich mit Inhalt aus einer Wiederherstellungsquelle wieder her. Wenn ein Pfad überwacht wird, aber in der Wiederherstellungsquelle nicht vorhanden ist, wird er entfernt, damit er mit der Quelle übereinstimmt.
Der Befehl kann auch verwendet werden, um den Inhalt im Index mit --staged wiederherzustellen oder um sowohl den Arbeitsbereich (working tree) als auch den Index mit --staged --worktree wiederherzustellen.
By default, if --staged is given, the contents are restored from HEAD, otherwise from the index. Use --source to restore from a different commit.
Siehe „Reset, restore und revert“ in git[1] für die unterschiedlichen Eigenschaften der drei Befehle.
DIESER BEFEHL IST EXPERIMENTELL. MÖGLICHERWEISE KANN SICH DAS VERHALTEN ÄNDERN.
OPTIONEN
- -s <Tree>
- --source=<Tree>
-
Wiederherstellen der Dateien des Arbeitsbereichs mit dem Inhalt aus dem angegebenen Daten-Baum. Es ist üblich, den Quellbaum durch Angabe eines assoziierten Commit-, Branch- oder Tag-Namens zu bestimmen.
If not specified, the contents are restored from
HEADif--stagedis given, otherwise from the index.As a special case, you may use
"A...B"as a shortcut for the merge base ofAandBif there is exactly one merge base. You can leave out at most one ofAandB, in which case it defaults toHEAD. - -p
- --patch
-
Wählt interaktiv abweichende Abschnitte in der Wiederherstellungsquelle und dem Wiederherstellungsort aus. Siehe den Abschnitt "Interaktiver Modus" in git-add[1], um zu erfahren, wie der
--patch-Modus anzuwenden ist.Note that
--patchcan accept no pathspec and will prompt to restore all modified paths. - -W
- --worktree
- -S
- --staged
-
Bestimmt den Wiederherstellungsort. Wenn keine der beiden Optionen angegeben wurde, stellt das System standardmäßig den Arbeitsbereich wieder her. Mit der Angabe von
--stagedwird nur den Index wieder hergestellt. Die Angabe beider Optionen stellt beides wieder her. - -q
- --quiet
-
Quiet, suppress feedback messages. Implies
--no-progress. - --progress
- --no-progress
-
Der Fortschritt wird standardmäßig auf der Standardfehlerausgabe angezeigt, wenn diese an ein Terminal angebunden ist, außer wenn
--quietangegeben ist. Dieses Flag erlaubt die Fortschrittsanzeige auch ohne Terminalanbindung, ohne--quietzu berücksichtigen. - --ours
- --theirs
-
When restoring files in the working tree from the index, use stage #2 (ours) or #3 (theirs) for unmerged paths. This option cannot be used when checking out paths from a tree-ish (i.e. with the
--sourceoption).Hinweis: Während eines
git rebaseund einesgit pull --rebasekönnen ours und theirs vertauscht erscheinen. Siehe die Beschreibung der gleichen Optionen in git-checkout[1] für weitere Details. - -m
- --merge
-
When restoring files on the working tree from the index, recreate the conflicted merge in the unmerged paths. This option cannot be used when checking out paths from a tree-ish (i.e. with the
--sourceoption). - --conflict=<style>
-
The same as
--mergeoption above, but changes the way the conflicting hunks are presented, overriding themerge.conflictStyleconfiguration variable. Possible values are "merge" (default), "diff3", and "zdiff3". - --ignore-unmerged
-
Wenn Dateien im Arbeitsbereich aus dem Index wiederhergestellt werden, sollte diese Operation nicht abgebrochen werden, wenn es nicht gemergte Einträge gibt und weder
--ours,--theirs,--mergenoch--conflictangegeben ist. Nicht verschmolzene Pfade auf dem Arbeitsbereich werden ignoriert. - --ignore-skip-worktree-bits
-
In sparse checkout mode, the default is to only update entries matched by
<pathspec>and sparse patterns in $GIT_DIR/info/sparse-checkout. This option ignores the sparse patterns and unconditionally restores any files in<pathspec>. - --recurse-submodules
- --no-recurse-submodules
-
If
<pathspec>names an active submodule and the restore location includes the working tree, the submodule will only be updated if this option is given, in which case its working tree will be restored to the commit recorded in the superproject, and any local modifications overwritten. If nothing (or--no-recurse-submodules) is used, submodules working trees will not be updated. Just like git-checkout[1], this will detachHEADof the submodule. - --overlay
- --no-overlay
-
Im Overlay-Modus werden mit diesem Befehl niemals Dateien beim Wiederherstellen entfernt. Im No-Overlay-Modus werden getrackte Dateien, die nicht im
--source-Tree vorkommen, entfernt, damit sie genau mit<Tree>übereinstimmen. Die Standardeinstellung ist der No-Overlay-Modus. - --pathspec-from-file=<Datei>
-
Die Pfadangabe wird in
<Datei>statt über Befehlszeilen-Argumente übergeben. Wenn<Datei>genau-ist, wird die Standardeingabe verwendet. Pfadspezifische Elemente werden durch LF oder CR/LF getrennt. Pathspec-Elemente können in Anführungszeichen gesetzt werden, wie für die Konfigurations-Variablecore.quotePathbeschrieben (siehe git-config[1]). Siehe auch--pathspec-file-nulund global--literal-pathspecs. - --pathspec-file-nul
-
Nur sinnvoll mit
--pathspec-from-file. Pfadspezifische Elemente werden mit dem Steuerzeichen-Code NULL getrennt und alle anderen Zeichen werden unverändert übernommen (einschließlich der Zeilenumbrüche und Anführungszeichen). - --
-
Diese Option kann dazu verwendet werden, Befehlszeilenoptionen von der Liste von Dateien zu trennen. Dies ist sinnvoll, wenn Dateinamen mit Befehlszeilenoptionen verwechselt werden könnten.
- <Pfadspezifikation>…
-
Legt die von der Operation betroffenen Pfade fest.
Mehr Details finden Sie im pathspec-Eintrag in gitglossary[7].
BEISPIELE
Das folgende Listing wechselt in den Branch master, setzt das Makefile um zwei Revisionsstände zurück, dann wird hello.c irrtümlich gelöscht, um danach wieder aus dem Index zurückgeholt zu werden.
$ git switch master $ git restore --source master~2 Makefile (1) $ rm -f hello.c $ git restore hello.c (2)
-
Lade eine Datei aus einem anderen Commit
-
Wiederherstellen von hello.c aus dem Index
Falls alle C-Quelldateien wieder hergestellt werden sollen, damit sie mit der Version im Index übereinstimmen, kann man folgendes eingeben
$ git restore '*.c'
Note the quotes around *.c. The file hello.c will also be restored, even though it is no longer in the working tree, because the file globbing is used to match entries in the index (not in the working tree by the shell).
So kann man alle Dateien im aktuellen Verzeichnis wieder herstellen
$ git restore .
or to restore all working tree files with top pathspec magic (see gitglossary[7])
$ git restore :/
Eine Datei im Index so wiederherstellen, dass sie mit der Version in HEAD übereinstimmt (das entspricht dem Vorgehen wie mit git-reset[1])
$ git restore --staged hello.c
or you can restore both the index and the working tree (this is the same as using git-checkout[1])
$ git restore --source=HEAD --staged --worktree hello.c
die Kurzform ist praktischer aber nicht so gut lesbar:
$ git restore -s@ -SW hello.c
GIT
Teil der git[1] Suite