目录 搜索
Guides gitattributes giteveryday gitglossary gitignore gitmodules gitrevisions gittutorial gitworkflows Administration git archive git bundle git clean git filter-branch git fsck git gc git instaweb git reflog Basic Snapshotting git add git commit git diff git mv git reset git rm git status Branching and Merging git branch git checkout git log git merge git mergetool git stash git tag Debugging git bisect git blame git grep Email git am git format-patch git request-pull git send-email External Systems git fast-import git svn Getting and Creating Projects git clone git init Git git annotate git archimport git bisect-lk2009 git check-attr git check-mailmap git check-ref-format git checkout-index git cherry git citool git column git credential git credential-cache git credential-store git cvsexportcommit git cvsimport git cvsserver git diff-files git diff-tree git difftool git fast-export git fetch-pack git fmt-merge-msg git get-tar-commit-id git gui git http-backend git http-fetch git http-push git imap-send git index-pack git interpret-trailers git ls-remote git ls-tree git mailinfo git mailsplit git merge-file git merge-index git merge-one-file git merge-tree git mktag git mktree git name-rev git notes git p4 git pack-objects git pack-redundant git pack-refs git parse-remote git patch-id git prune git prune-packed git quiltimport git receive-pack git remote-ext git remote-fd git remote-testgit git repack git replace git rerere git send-pack git sh-i18n git sh-setup git shell git show-branch git show-index git stripspace git unpack-file git unpack-objects git upload-archive git upload-pack git var git verify-commit git verify-tag git whatchanged git worktree Inspection and Comparison git describe git shortlog git show Miscellaneous api credentials api index gitcli gitcore tutorial gitcredentials gitcvs migration gitdiffcore githooks gitk gitnamespaces gitremote helpers gitrepository layout gitsubmodules gittutorial 2 gitweb gitweb.conf pack format User Manual Patching git apply git cherry-pick git rebase git revert Plumbing Commands git cat-file git check-ignore git commit-tree git count-objects git diff-index git for-each-ref git hash-object git ls-files git merge-base git read-tree git rev-list git rev-parse git show-ref git symbolic-ref git update-index git update-ref git verify-pack git write-tree Server Admin git daemon git update-server-info Setup and Config git git config git help Sharing and Updating Projects git fetch git pull git push git remote git submodule
文字

命名

git-revert  - 恢复一些现有的提交

概要

git revert [--[no-]edit] [-n] [-m parent-number] [-s] [-S[<keyid>]] <commit>…
git revert --continuegit revert --quit
git revert --abort

描述

给定一个或多个现有的提交,恢复相关修补程序引入的更改,并记录一些记录它们的新提交。这要求你的工作树是干净的(不需要修改 HEAD 提交)。

注意:git revert用于记录一些新的提交以反转一些早期提交的影响(通常只是错误的提交)。如果你想扔掉工作目录中所有未提交的更改,你应该看到 git-reset [1],特别是--hard选项。如果你想提取特定文件,就像在另一个提交中那样,你应该看到 git-checkout [1],特别是git checkout <commit> -- <filename>语法。请谨慎使用这些替代方法,因为它们都会丢弃工作目录中的未提交更改。

选项

<commit>…

承诺恢复。有关拼写提交名称的更完整列表,请参阅 gitrevisions [7]。提交集也可以给出,但默认情况下不进行遍历,参见 git-rev-list [1] 及其--no-walk选项。

-e   --edit

使用此选项,git revert将允许您在提交还原之前编辑提交消息。如果您从终端运行命令,这是默认值。

-m parent-number   --mainline parent-number

通常您无法恢复合并,因为您不知道合并的哪一方应被视为主线。此选项指定主线路的父代号码(从1开始),并允许还原以相对于指定的父代的相反更改。

恢复合并提交声明您将永远不希望合并引入的树更改。因此,稍后的合并只会引入不是先前还原合并的祖先的提交引入的树更改。这可能是也可能不是你想要的。

有关更多详细信息,请参阅恢复错误合并的方法

--no-edit

使用此选项,git revert将不会启动提交消息编辑器。

-n   --no-commit

通常,该命令会自动创建一些提交日志消息,提交哪些提交已恢复。此标志应用必要的更改以将命名的提交恢复到您的工作树和索引,但不进行提交。此外,使用此选项时,您的索引不必与 HEAD 提交匹配。回复是针对索引的开始状态完成的。

将多个提交的效果还原为连续的索引时,这非常有用。

-S<keyid>   --gpg-sign=<keyid>

GPG 标志提交。该keyid参数是可选的,并且默认为提交者身份; 如果指定,它必须粘贴到选项没有空格。

-s   --signoff

在提交消息的末尾添加 Signed-off-by 行。有关更多信息,请参阅 git-commit [1] 中的 signoff 选项。

--strategy=<strategy>

使用给定的合并策略。只能使用一次。有关详细信息,请参阅 git-merge [1] 中的 MERGE STRATEGIES 部分。

-X<option>   --strategy-option=<option>

将合并策略特定选项传递给合并策略。有关详细信息,请参阅 git-merge [1]。

Sequencer子命令

--continue

使用中的信息继续正在进行的操作.git/sequencer。可以在解决失败的 cherry-pick 或恢复中的冲突后继续使用。

--quit

忘记当前正在进行的操作。在 cherry-pick 或恢复失败后可用于清除音序器状态。

--abort

取消操作并返回到预序列状态。

例子

git revert HEAD~3

恢复 HEAD 中最后第四次提交指定的更改,并使用恢复的更改创建一个新的提交。

git revert -n master~5..master~2

将提交完成的更改从 master(包含)中的第五次提交恢复为 master(包含)中的第三次提交,但不要使用已还原的更改创建任何提交。恢复只修改工作树和索引。

上一篇: 下一篇: