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.44.0 02/23/24
- 2.43.1 → 2.43.3 no changes
- 2.43.0 11/20/23
- 2.39.1 → 2.42.1 no changes
- 2.39.0 12/12/22
- 2.38.1 → 2.38.5 no changes
- 2.38.0 10/02/22
- 2.37.1 → 2.37.7 no changes
- 2.37.0 06/27/22
- 2.30.1 → 2.36.6 no changes
- 2.30.0 12/27/20
- 2.27.1 → 2.29.3 no changes
- 2.27.0 06/01/20
概述
git revert [--[no-]edit] [-n] [-m <父提交数量>] [-s] [-S[<键 ID>]] <提交>… git revert (--continue | --skip | --abort | --quit)
描述
Given one or more existing commits, revert the changes that the related patches introduce, and record some new commits that record them. This requires your working tree to be clean (no modifications from the HEAD commit).
Note: git revert is used to record some new commits to reverse the effect of some earlier commits (often only a faulty one). If you want to throw away all uncommitted changes in your working directory, you should see git-reset[1], particularly the --hard
option. If you want to extract specific files as they were in another commit, you should see git-restore[1], specifically the --source
option. Take care with these alternatives as both will discard uncommitted changes in your working directory.
关于这三个命令的区别,见git[1]中的 "重置、恢复和还原"。
选项
- <提交>…
-
Commits to revert. For a more complete list of ways to spell commit names, see gitrevisions[7]. Sets of commits can also be given but no traversal is done by default, see git-rev-list[1] and its
--no-walk
option. - -e
- --edit
-
有了这个选项,git revert 会让你在提交之前编辑提交信息。如果从终端运行该命令,默认情况下也是如此。
- -m 父编号
- --mainline parent-number
-
Usually you cannot revert a merge because you do not know which side of the merge should be considered the mainline. This option specifies the parent number (starting from 1) of the mainline and allows revert to reverse the change relative to the specified parent.
Reverting a merge commit declares that you will never want the tree changes brought in by the merge. As a result, later merges will only bring in tree changes introduced by commits that are not ancestors of the previously reverted merge. This may or may not be what you want.
更多详情,请参阅 revert-a-faulty-merge 如何操作。
- --no-edit
-
使用该选项后,git revert 将不会启动提交信息编辑器。
- --cleanup=<模式>
-
这个选项决定了提交信息在传递给提交机制之前将如何进行清理。更多细节见 git-commit[1]。特别是,如果 <模式> 的值为
scissors
,那么在发生冲突时,scissors
将被附加到MERGE_MSG
上。 - -n
- --no-commit
-
Usually the command automatically creates some commits with commit log messages stating which commits were reverted. This flag applies the changes necessary to revert the named commits to your working tree and the index, but does not make the commits. In addition, when this option is used, your index does not have to match the HEAD commit. The revert is done against the beginning state of your index.
这在连续恢复多个提交对索引的影响时非常有用。
- -S[<keyid>]
- --gpg-sign[=<键 ID>]
- --no-gpg-sign
-
GPG 签名提交。
keyid
参数是可选的,默认为提交者身份;如果指定了,则必须与选项相连,不加空格。--no-gpg-sign
用于还原commit.gpgSign
配置变量和先前的--gpg-sign
。 - -s
- --signoff
-
Add a
Signed-off-by
trailer at the end of the commit message. See the signoff option in git-commit[1] for more information. - --strategy=<策略>
-
Use the given merge strategy. Should only be used once. See the MERGE STRATEGIES section in git-merge[1] for details.
- -X<选项>
- --strategy-option=<选项>
-
Pass the merge strategy-specific option through to the merge strategy. See git-merge[1] for details.
- --rerere-autoupdate
- --no-rerere-autoupdate
-
在 rerere 机制重用当前冲突的记录解析来更新工作树中的文件后,允许它也用解析的结果来更新索引。
--no-rerere-autoupdate`是一个很好的方法,在用单独的 `git add
提交结果到索引之前,可以反复检查rerere
所做的事情,并抓住潜在的错误合并。
- --reference
-
Instead of starting the body of the log message with "This reverts <full-object-name-of-the-commit-being-reverted>.", refer to the commit using "--pretty=reference" format (cf. git-log[1]). The
revert.reference
configuration variable can be used to enable this option by default.
讨论
While git creates a basic commit message automatically, it is strongly recommended to explain why the original commit is being reverted. In addition, repeatedly reverting reverts will result in increasingly unwieldy subject lines, for example Reapply "Reapply "<original-subject>"". Please consider rewording these to be shorter and more unique.
配置
Warning
|
Missing See original version for this content. |
Warning
|
Missing See original version for this content. |
GIT
属于 git[1] 文档