精华内容
下载资源
问答
  • Git 之 revert

    2019-12-27 10:33:24
    revert 可以取消指定的提交内容。 当讨论 revert 时,需要分两种情况,因为 commit 分为两种:一种是常规的 commit,也就是使用 git commit 提交的 commit;另一种是 merge commit,在使用 git merge 合并两个分支...

    revert 可以取消指定的提交内容。

    当讨论 revert 时,需要分两种情况,因为 commit 分为两种:一种是常规的 commit,也就是使用 git commit 提交的 commit;另一种是 merge commit,在使用 git merge 合并两个分支之后,你将会得到一个新的 merge commit

    merge commit 和普通 commit 的不同之处在于 merge commit 包含两个 parent commit,代表该 merge commit 是从哪两个 commit 合并过来的。

    在这里插入图片描述

    在上图所示的红框中有一个 merge commit,使用 git show 命令可以查看 commit 的详细信息

    ➜  git show bd86846
    commit bd868465569400a6b9408050643e5949e8f2b8f5
    Merge: ba25a9d 1c7036f
    

    这代表该 merge commit 是从 ba25a9d 和 1c7036f 两个 commit 合并过来的。

    而常规的 commit 则没有 Merge 行

    ➜  git show 3e853bd
    commit 3e853bdcb2d8ce45be87d4f902c0ff6ad00f240a
    

    revert 常规 commit

    使用 git revert 即可,git 会生成一个新的 commit,将指定的 commit 内容从当前分支上撤除。

    revert merge commit

    revert merge commit 有一些不同,这时需要添加 -m 选项以代表这次 revert 的是一个 merge commit

    但如果直接使用 git revert ,git 也不知道到底要撤除哪一条分支上的内容,这时需要指定一个 parent number 标识出"主线",主线的内容将会保留,而另一条分支的内容将被 revert。

    如上面的例子中,从 git show 命令的结果中可以看到,merge commit 的 parent 分别为 ba25a9d 和 1c7036f,其中 ba25a9d 代表 master 分支(从图中可以看出),1c7036f 代表 will-be-revert 分支。需要注意的是 -m 选项接收的参数是一个数字,数字取值为 1 和 2,也就是 Merge 行里面列出来的第一个还是第二个。

    我们要 revert will-be-revert 分支上的内容,即 保留主分支,应该设置主分支为主线,操作如下:
    ➜ git revert -m 1 bd86846

    revert 之后重新上线

    假设狗蛋在自己分支 goudan/a-cool-feature 上开发了一个功能,并合并到了 master 上,之后 master 上又提交了一个修改 h,这时提交历史如下:

    a -> b -> c -> f -- g -> h (master)
               \      /
                d -> e   (goudan/a-cool-feature)
    

    突然,大家发现狗蛋的分支存在严重的 bug,需要 revert 掉,于是大家把 g 这个 merge commit revert 掉了,记为 G,如下:

    a -> b -> c -> f -- g -> h -> G (master)
               \      /
                d -> e   (goudan/a-cool-feature)
    

    然后狗蛋回到自己的分支进行 bugfix,修好之后想重新合并到 master,直觉上只需要再 merge 到 master 即可(或者使用 cherry-pick),像这样:

    a -> b -> c -> f -- g -> h -> G -> i (master)
               \      /               /
                d -> e -> j -> k ----    (goudan/a-cool-feature)
    

    i 是新的 merge commit。但需要注意的是,这 不能 得到我们期望的结果。因为 d 和 e 两个提交曾经被丢弃过,如此合并到 master 的代码,并不会重新包含 d 和 e 两个提交的内容,相当于只有 goudan/a-cool-feature 上的新 commit 被合并了进来,而 goudan/a-cool-feature 分支之前的内容,依然是被 revert 掉了。

    所以,如果想恢复整个 goudan/a-cool-feature 所做的修改,应该先把 G revert 掉:

    a -> b -> c -> f -- g -> h -> G -> G' -> i (master)
               \      /                     /
                d -> e -> j -> k ----------    (goudan/a-cool-feature)
    

    其中 G’ 是对 G 的 revert 操作生成的 commit,把之前撤销合并时丢弃的代码恢复了回来,然后再 merge 狗蛋的分支,把解决 bug 写的新代码合并到 master 分支。

    参考:

    http://blog.psjay.com/posts/git-revert-merge-commit/

    https://stackoverflow.com/questions/9059335/get-parents-of-a-merge-commit-in-git

    展开全文
  • git revert

    千次阅读 2013-09-05 22:56:00
    NAME ... git-revert - Revert an existing commit SYNOPSIS  git revert [--edit | --no-edit] [-n] [-m parent-number] [-s] DESCRIPTION  Given one existing commit, revert the c
    NAME
           git-revert - Revert an existing commit


    SYNOPSIS
           git revert [--edit | --no-edit] [-n] [-m parent-number] [-s] <commit>


    DESCRIPTION
           Given one existing commit, revert the change the patch introduces, and
           record a new commit that records it
    . This requires your working tree to
           be clean (no modifications from the HEAD commit).


           Note: git revert is used to record a new commit to reverse the effect
           of an earlier commit (often 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-
           checkout(1), specifically the git checkout <commit> — <filename>
           syntax. Take care with these alternatives as both will discard
           uncommitted changes in your working directory.


    OPTIONS
           <commit>
      Commit to revert. For a more complete list of ways to spell commit
      names, see "SPECIFYING REVISIONS" section in git-rev-parse(1).


           -e, --edit
      With this option, git revert will let you edit the commit message
      prior to committing the revert. This is the default if you run the
      command from a terminal.


           -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[1] for more details.


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


           -n, --no-commit
      Usually the command automatically creates a commit with a commit
      log message stating which commit was reverted. This flag applies
      the change necessary to revert the named commit to your working
      tree and the index, but does not make the commit. 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, --signoff
      Add Signed-off-by line at the end of the commit message.
    展开全文
  • I was trapped by the following scenario: I had a new set update to the production version, let's say revision 371 A couple of changes are just reverting files back to revision ... So I just revert ...

    I was trapped by the following scenario:

    I had a new set update to the production version, let's say revision 371

    A couple of changes are just reverting files back to revision 369. So I just revert the files in my working copy back to revision 369.

    Few weeks later client approved all changes and request me to implement. 

    I just right click my working copy and run "Check For Modifications", the changes files listed would be transferred to production environment.

    However today I realised the file revertted back to revision 369 were not implemented. I thought it is just my oversight and not see those changes.

    But the reverted file do have green tick meaning there were no changes to them.

    After reading the explaination on web, It shows the revert file are not treated as changes.

     

    ***I learnt that we also need to run "Check For Modifications" then click "Check Repository" and this can show the difference to the latest version on repository.

     

    To prevent the issue and do the committable revert, following inform works for me:

    http://tortoisesvn.net/docs/nightly/TortoiseSVN_en/tsvn-howto-rollback.html

    Roll back (Undo) revisions in the repository

    Use the revision log dialog

    By far the easiest way to revert the changes from one or more revisions, is to use the revision log dialog.

    1. Select the file or folder in which you need to revert the changes. If you want to revert all changes, this should be the top level folder.

    2. Select TortoiseSVN → Show Log to display a list of revisions. You may need to use Show All or Next 100 to show the revision(s) you are interested in.

    3. Select the revision you wish to revert. If you want to undo a range of revisions, select the first one and hold the Shift key while selecting the last one. If you want to pick out individual revisions and ranges, use the Ctrl key while selecting revisions.Right click on the selected revision(s), then select Context Menu → Revert changes from this revision.

    4. Or if you want to make an earlier revision the new HEAD revision, right click on the selected revision, then select Context Menu → Revert to this revision. This will discard all changes after the selected revision.

    You have reverted the changes within your working copy. Check the results, then commit the changes.

     

    Use the merge dialog

    If you want to enter revision numbers as a list, you can use the Merge dialog. The previous method uses merging behind the scenes; this method uses it explicitly.

    1. In your working copy select TortoiseSVN → Merge.

    2. In the Merge Type dialog select Merge a range of revisions.

    3. In the From: field enter the full repository URL of your working copy folder. This should come up as the default URL.

    4. In the Revision range to merge field enter the list of revisions to roll back (or use the log dialog to select them as described above).

    5. Make sure the Reverse merge checkbox is checked.

    6. In the Merge options dialog accept the defaults.

    7. Click Merge to complete the merge.

    You have reverted the changes within your working copy. Check that the results are as expected, then commit the changes.

    Use svndumpfilter

    Since TortoiseSVN never loses data, your rolled back” revisions still exist as intermediate revisions in the repository. Only the HEAD revision was changed to a previous state. If you want to make revisions disappear completely from your repository, erasing all trace that they ever existed, you have to use more extreme measures. Unless there is a really good reason to do this, it is not recommended. One possible reason would be that someone committed a confidential document to a public repository.

    The only way to remove data from the repository is to use the Subversion command line toolsvnadmin. You can find a description of how this works in the Repository Maintenance .

    转载于:https://www.cnblogs.com/yangbin990/p/4276302.html

    展开全文
  • Git 之 revert (撤销commit或merge) revert 可以取消指定的提交内容。 当讨论 revert 时,需要分两种情况,因为 commit 分为两种:一种是常规的 commit,也就是使用git commit提交的 commit;另一种是merge commit...

    revert 可以取消指定的提交内容。

    当讨论 revert 时,需要分两种情况,因为 commit 分为两种:一种是常规的 commit,也就是使用 git commit 提交的 commit;另一种是 merge commit,在使用 git merge 合并两个分支之后,你将会得到一个新的 merge commit

    merge commit 和普通 commit 的不同之处在于 merge commit 包含两个 parent commit,代表该 merge commit 是从哪两个 commit 合并过来的。

    clipboard.png

    在上图所示的红框中有一个 merge commit,使用 git show 命令可以查看 commit 的详细信息

     
    1. ➜ git show bd86846

    2. commit bd868465569400a6b9408050643e5949e8f2b8f5

    3. Merge: ba25a9d 1c7036f

    这代表该 merge commit 是从 ba25a9d 和 1c7036f 两个 commit 合并过来的。

    而常规的 commit 则没有 Merge 行

     
    1. ➜ git show 3e853bd

    2. commit 3e853bdcb2d8ce45be87d4f902c0ff6ad00f240a

    revert 常规 commit

    使用 git revert <commit id> 即可,git 会生成一个新的 commit,将指定的 commit 内容从当前分支上撤除。

    revert merge commit

    revert merge commit 有一些不同,这时需要添加 -m 选项以代表这次 revert 的是一个 merge commit

    但如果直接使用 git revert <commit id>,git 也不知道到底要撤除哪一条分支上的内容,这时需要指定一个 parent number 标识出"主线",主线的内容将会保留,而另一条分支的内容将被 revert。

    如上面的例子中,从 git show 命令的结果中可以

    ➜ git show bd86846

    看到,merge commit 的 parent 分别为 ba25a9d 和 1c7036f,其中 ba25a9d 代表 master 分支(从图中可以看出),1c7036f 代表 will-be-revert 分支。需要注意的是 -m 选项接收的参数是一个数字,数字取值为 1 和 2,也就是 Merge 行里面列出来的第一个还是第二个。

    我们要 revert will-be-revert 分支上的内容,即 保留主分支,应该设置主分支为主线,操作如下:

    ➜ git revert -m 1 bd86846

    revert 之后重新上线

    假设狗蛋在自己分支 goudan/a-cool-feature 上开发了一个功能,并合并到了 master 上,之后 master 上又提交了一个修改 h,这时提交历史如下:

     
    1. a -> b -> c -> f -- g -> h (master)

    2. \ /

    3. d -> e (goudan/a-cool-feature)

    突然,大家发现狗蛋的分支存在严重的 bug,需要 revert 掉,于是大家把 g 这个 merge commit revert 掉了,记为 G,如下:

     
    1. a -> b -> c -> f -- g -> h -> G (master)

    2. \ /

    3. d -> e (goudan/a-cool-feature)

    然后狗蛋回到自己的分支进行 bugfix,修好之后想重新合并到 master,直觉上只需要再 merge 到 master 即可(或者使用 cherry-pick),像这样:

     
    1. a -> b -> c -> f -- g -> h -> G -> i (master)

    2. \ / /

    3. d -> e -> j -> k ---- (goudan/a-cool-feature)

    i 是新的 merge commit。但需要注意的是,这 不能 得到我们期望的结果。因为 d 和 e 两个提交曾经被丢弃过,如此合并到 master 的代码,并不会重新包含 d 和 e 两个提交的内容,相当于只有 goudan/a-cool-feature 上的新 commit 被合并了进来,而 goudan/a-cool-feature 分支之前的内容,依然是被 revert 掉了。

    所以,如果想恢复整个 goudan/a-cool-feature 所做的修改,应该先把 G revert 掉:

     
    1. a -> b -> c -> f -- g -> h -> G -> G' -> i (master)

    2. \ / /

    3. d -> e -> j -> k ---------- (goudan/a-cool-feature)

    其中 G' 是对 G 的 revert 操作生成的 commit,把之前撤销合并时丢弃的代码恢复了回来,然后再 merge 狗蛋的分支,把解决 bug 写的新代码合并到 master 分支。

    参考

    http://blog.psjay.com/posts/git-revert-merge-commit/

    https://stackoverflow.com/questions/9059335/get-parents-of-a-merge-commit-in-git

    展开全文
  • 参考下面两个问答:http://stackoverflow.com/questions/8139605/does-svn-have-a-revert-all-command-----------------------------------You could do:svn revert -R .This will not delete any new file not ...
  • Git:git-revert的用法总结

    千次阅读 2018-07-24 22:14:09
    git-revert - Revert some existing commits // 撤销一些已经存在的提交 语法 git revert [--[no-]edit] [-n] [-m parent-number] [-s] [-S[&amp;amp;lt;keyid&amp;amp;gt;]] &amp;amp;lt;commit&...
  • Git对MR进行revert

    2020-08-26 20:49:42
    Git对MR进行revert revert 可以取消指定的某次提交内容。 当讨论 revert 时,需要分两种情况,因为 commit 分为两种:一种是常规的 commit,也就是使用 git commit 提交的 commit;另一种是 merge commit,在使用 ...
  • 关于 “VM resize revert 失败” 问题的分析 作者:张航东 版本: Kilo 2015.1.1   1. Problem When we tested Kilo 2015.1.1, we met an error (randomly) about resize-revert function. The error finally ...
  • git revert 踩坑之路

    千次阅读 2020-01-21 15:18:15
    在实际的开发工作中,使用git总会遇到一堆问题,本文将结合具体例子,讲述在何种条件下会出发git revert失败以及解决的方案和措施。 准备工作 首先,创建一个git 仓库(repo),本人是在Mac环境下,Windows下打开git...
  • 【git revert】使用以及理解(详解)

    千次阅读 2020-12-18 15:50:43
    如果想把B,C,D都给revert,除了一个一个revert之外,还可以使用range revert git revert B^…D 这样就把B,C,D都给revert了,变成: A-> B ->C -> D -> D’-> C’ -> B’ 用法就是: git revert ...
  • 在利用github实现多人合作程序开发的过程中,我们有时会出现错误提交的情况,此时我们希望能撤销提交操作,让程序回到提交前的样子,本文总结了两种解决方法:回退(reset)、反做(revert)。 背景知识 git的...
  • 在利用github实现多人合作程序开发的过程中,我们有时会出现错误提交的情况,此时我们希望能撤销提交操作,让程序回到提交前的样子,本文总结了两种解决方法:回退(reset)、反做(revert)。 二、背景知识 git的...
  • Commit, stash or revert them to proceed. 代码冲突,如果提交,就会将本地代码覆盖掉,所以需要先将本地代码备份,然后更新代码,最后合并代码 1.备份本地代码,备份后本地代码自动隐藏,代码自动回归到上一个...
  • Chrome 84+: CSS revert value

    2021-01-11 06:12:26
    Therefore draft pull request, but it worked before (before the first VCS-revert) and probably will again in the next build. Will update then.~ <p>There we go, 84.0.4120.0: <p><img alt="image" src=...
  • will-change通过告知浏览器该元素会有哪些变化,使浏览器提前做好优化准备,增强页面渲染性能。 属性的取值: 1、auto: 实行标准浏览器优化。 2、scroll-position: 表示开发者希望在不久后改变滚动条的位置或者使之...
  • git checkout/git reset/git revert/git restore常用回退操作

    千次阅读 多人点赞 2020-03-07 18:48:32
    文章目录 前言 代码回退 Git管理下的各种文件状态 Git回退命令 git checkout git revert git restore git reset git rm 具体回退操作 初始状态 还原00:工作区中未加到暂存区和版本库的文件,还原今天所做的修改 ...
  • svn revert 还原整个目录

    千次阅读 2014-05-09 11:23:34
    参考下面两个问答: http://stackoverflow.com/questions/8139605/does-svn-have-a-revert-all-command ----------------------------------- You could do: ...This will not delete any new file no...
  • 【SVN命令】之 revert

    千次阅读 2013-12-21 15:34:32
    名称 子命令Svn revert — 取消所有的本地编辑。 概要 子命令Svn revert PATH......Reverts any local changes to a file or directory and resolves any ... Svn revert will revert not only the contents of an i
  • git revert 让提交不再害怕 使用了好多命令, 但对于 git revert 一直不敢怎么使用, 为什么呢? 因为 git merge 的存在. 每次 对于 git merge 的分支, 执行 git revert xxx 分支的时候总是报错. 没有细追. 今天同事...
  • pull代码,出现: 第一步。储存我自己的修改步。 先把 我们的修改 Stash 。存储起来。。你操作完了。发现项目是修改前的了。。 第二步:Pull 更新完成以后。 第三步:取出我们的修改。......
  • git reset&git revert 使用

    千次阅读 2017-03-27 17:13:44
    前言不管在工作还是个人开发的使用中,或多或少的...当然,如果版本控制连这种功能都没有的话,也就可以淘汰了,好的,废话不多说,接下来就来介绍今天的主角:git reset跟git revert的使用以及区别! 博主经历我是因
  • Commit, stash or revert them to proceed. 显示。如果Pull 成功会把我修改的代码覆盖。所以。按照提示。通过Android Studio 处理。第一步。先把 我们的修改 Stash 。存储起来。。你操作...
  • svn revert整个目录

    千次阅读 2014-02-24 09:42:40
    原文地址:... ...子命令Svn revert — 取消所有的本地编辑。...子命令Svn revert PATH...描述 Reverts any local changes to a file or directory and resolves any conflict
  • 在Solidity0.4.10之前,if...throw普遍利用于判断一个条件是否满足,...之后,assert(), require(), and revert() 三个函数代替了if...throw的功能,并对gas有了更好的处理。原文章中提到的例子: if(msg.sender !...
  • If you select the commit 2 and choose "Revert to this revision", your working copy will contain the changes brought by commits 1 and 2. Commits 3 and 4 will be "canceled". If you select the commit 2 ...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 9,525
精华内容 3,810
关键字:

revertwill