GIT打补丁之git-revert

名称NAME

git-revert - 还原一些现有的提交

概要SYNOPSIS

git revert [--[no-]edit] [-n] [-m parent-number] [-s] [-S[<keyid>]] <commit>…​
git revert (--continue | --skip | --abort | --quit)

描述DESCRIPTION

给定一个或多个已存在的提交,还原相关补丁引入的更改,并记录一些新的提交来记录它们。 这要求您的工作树是干净的(HEAD提交没有任何修改)。

注意:git revert用于记录一些新的提交,以逆转一些较早提交的效果(通常只有一个错误的提交)。 如果要丢弃工作目录中所有未提交的更改,则应该看到git-reset [1],尤其是--hard选项。 如果要提取特定文件,就像它们在另一个提交中一样,则应该看到git-restore [1],特别是--source选项。 请谨慎使用这些替代方法,因为这两种方法都会丢弃工作目录中未提交的更改。

选项OPTIONS

<commit>…​

要还原的提交

-e

--edit

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

-m parent-number

--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.

See the revert-a-faulty-merge How-To for more details.

--no-edit

With this option, git revert will not start the commit message editor.

--cleanup=<mode>

This option determines how the commit message will be cleaned up before being passed on to the commit machinery. See git-commit[1] for more details. In particular, if the <mode> is given a value of scissors, scissors will be appended to MERGE_MSG before being passed on in the case of a conflict.

-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.

This is useful when reverting more than one commits' effect to your index in a row.

-S[<keyid>]

--gpg-sign[=<keyid>]

GPG-sign commits. The keyid argument is optional and defaults to the committer identity; if specified, it must be stuck to the option without a space.

-s

--signoff

Add Signed-off-by line at the end of the commit message. See the signoff option in git-commit[1] for more information.

--strategy=<strategy>

Use the given merge strategy. Should only be used once. See the MERGE STRATEGIES section in git-merge[1] for details.

-X<option>

--strategy-option=<option>

Pass the merge strategy-specific option through to the merge strategy. See git-merge[1] for details.

--rerere-autoupdate

--no-rerere-autoupdate

Allow the rerere mechanism to update the index with the result of auto-conflict resolution if possible.

SEQUENCER SUBCOMMANDS

--continue

Continue the operation in progress using the information in .git/sequencer. Can be used to continue after resolving conflicts in a failed cherry-pick or revert.

--skip

Skip the current commit and continue with the rest of the sequence.

--quit

Forget about the current operation in progress. Can be used to clear the sequencer state after a failed cherry-pick or revert.

--abort

Cancel the operation and return to the pre-sequence state.

例子EXAMPLES

git revert HEAD~3

还原HEAD中倒数第四个提交指定的更改,并使用恢复的更改创建一个新的提交。

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

Revert the changes done by commits from the fifth last commit in master (included) to the third last commit in master (included), but do not create any commit with the reverted changes. The revert only modifies the working tree and the index.

将从master中的倒数第五个提交(包括)到master中的倒数第三个提交(包括)所做的更改进行还原,但不要使用还原后的更改创建任何提交。 还原仅修改工作树和索引。

发布了243 篇原创文章 · 获赞 138 · 访问量 138万+

猜你喜欢

转载自blog.csdn.net/ystyaoshengting/article/details/104120444
今日推荐