' git还原'什么都没有改变,只会添加一个新的提交

发布于 2025-02-03 17:49:23 字数 4330 浏览 5 评论 0原文

我正在从事一个项目,我想恢复到较早的提交。 This is the git log

commit a342294cbf25550f48452807d33a64f0c0248c34 (origin/master)
Author: analysis230 <[email protected]>
Date:   Thu Jun 2 13:51:52 2022 +0530

    added a toggle for viewport only visbility change

commit 4b5ce6478fb2692d03e084eabce636f859650af5
Author: analysis230 <[email protected]>
Date:   Thu Jun 2 13:50:17 2022 +0530

    added a toggle for viewport only visbility change

commit 1bc90dd971ea1bbb36cdd280f141cb4cc317ce0f
Author: analysis230 <[email protected]>
Date:   Wed Jun 1 23:53:21 2022 +0530

    changed git ignore

My head was at commit a342294cbf25550f48452807d33a64f0c0248c34 and I wanted to revert to 1bc90dd971ea1bbb36cdd280f141cb4cc317ce0f

I executed git revert HEAD~2 我有足够的空间写新消息,我写了一条提交消息,期望所有文件现在看起来都像在提交1BC90D971EA1BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB4CC317CE0F所有文件看起来都像提交A342294CBF255550F48452807D33A64F0C0248C34,但它在日志中显示了一个新提交。这是日志:

commit 6ee3550ad817839afbebe2b039653c4f00f3c074 (HEAD -> master)
Author: analysis230 <[email protected]>
Date:   Thu Jun 2 15:10:43 2022 +0530

    Revert "changed git ignore" Because for some reason the model doesn't load in blender with the new changes.
    Would look over the Coin class

    This reverts commit 1bc90dd971ea1bbb36cdd280f141cb4cc317ce0f.

commit a342294cbf25550f48452807d33a64f0c0248c34 (origin/master)
Author: analysis230 <[email protected]>
Date:   Thu Jun 2 13:51:52 2022 +0530

    added a toggle for viewport only visbility change

commit 4b5ce6478fb2692d03e084eabce636f859650af5
Author: analysis230 <[email protected]>
Date:   Thu Jun 2 13:50:17 2022 +0530

    added a toggle for viewport only visbility change

commit 1bc90dd971ea1bbb36cdd280f141cb4cc317ce0f
Author: analysis230 <[email protected]>
Date:   Wed Jun 1 23:53:21 2022 +0530

    changed git ignore

如果我做git Checkout 1BC90D971EA1BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB41CB4CC317CE0F ,我看到了我希望在还原后看到的文件版本。这是一个示例:

当我结帐1BC90D971EA1BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB41CB4CC317CE0F 时,这就是我在一个文件中看到的。

class ParamNames:
    widthOffset = "WidthOffset"
    heightOffset = "HeightOffset"
    precision = "Precision"
    seamAbberations = "Seam Abberations"

    amount = "Amount"
    probability = "Probability"

class Keywords:
    layerNumber = "layerNumber"

上恢复IE之后结帐Master Branch。

from random import Random

class ParamNames:
    widthOffset = "WidthOffset"
    heightOffset = "HeightOffset"
    precision = "Precision"
    seamAbberations = "Seam Abberations"

    amount = "Amount"
    probability = "Probability"

    seed = "Seed"

class Keywords:
    layerNumber = "layerNumber"

class BiasedCoin:
    def __init__(self, seed):
        self.randGenerator = Random()
        self.randGenerator.seed = seed

    def toss(self, headProb):
        weights = [100-headProb, headProb]
        return self.randGenerator.choices([0,1], weights=weights)[0]

    def uniform(self,a,b):
        return self.randGenerator.uniform(a,b)

当我在提交A342294CBF25550F48452807D33A64F0C0248C34

I'm working on a project and I wanted to revert back to an earlier commit.
This is the git log

commit a342294cbf25550f48452807d33a64f0c0248c34 (origin/master)
Author: analysis230 <[email protected]>
Date:   Thu Jun 2 13:51:52 2022 +0530

    added a toggle for viewport only visbility change

commit 4b5ce6478fb2692d03e084eabce636f859650af5
Author: analysis230 <[email protected]>
Date:   Thu Jun 2 13:50:17 2022 +0530

    added a toggle for viewport only visbility change

commit 1bc90dd971ea1bbb36cdd280f141cb4cc317ce0f
Author: analysis230 <[email protected]>
Date:   Wed Jun 1 23:53:21 2022 +0530

    changed git ignore

My head was at commit a342294cbf25550f48452807d33a64f0c0248c34 and I wanted to revert to 1bc90dd971ea1bbb36cdd280f141cb4cc317ce0f

I executed git revert HEAD~2
I got the space to write a new message and I wrote a commit message expecting that all the files should now look like they did in commit 1bc90dd971ea1bbb36cdd280f141cb4cc317ce0f, but they don't. All the files look like commit a342294cbf25550f48452807d33a64f0c0248c34 but it shows a new commit in the log. Here's the log:

commit 6ee3550ad817839afbebe2b039653c4f00f3c074 (HEAD -> master)
Author: analysis230 <[email protected]>
Date:   Thu Jun 2 15:10:43 2022 +0530

    Revert "changed git ignore" Because for some reason the model doesn't load in blender with the new changes.
    Would look over the Coin class

    This reverts commit 1bc90dd971ea1bbb36cdd280f141cb4cc317ce0f.

commit a342294cbf25550f48452807d33a64f0c0248c34 (origin/master)
Author: analysis230 <[email protected]>
Date:   Thu Jun 2 13:51:52 2022 +0530

    added a toggle for viewport only visbility change

commit 4b5ce6478fb2692d03e084eabce636f859650af5
Author: analysis230 <[email protected]>
Date:   Thu Jun 2 13:50:17 2022 +0530

    added a toggle for viewport only visbility change

commit 1bc90dd971ea1bbb36cdd280f141cb4cc317ce0f
Author: analysis230 <[email protected]>
Date:   Wed Jun 1 23:53:21 2022 +0530

    changed git ignore

if I do git checkout 1bc90dd971ea1bbb36cdd280f141cb4cc317ce0f, I see the version of the file that I expect to see after the revert. Here's an example:

when I checkout 1bc90dd971ea1bbb36cdd280f141cb4cc317ce0f, this is what I see in one of my files.

class ParamNames:
    widthOffset = "WidthOffset"
    heightOffset = "HeightOffset"
    precision = "Precision"
    seamAbberations = "Seam Abberations"

    amount = "Amount"
    probability = "Probability"

class Keywords:
    layerNumber = "layerNumber"

when I checkout master branch after the revert i.e. on commit a342294cbf25550f48452807d33a64f0c0248c34, the same file looks like this, which is all the changes I want to remove:

from random import Random

class ParamNames:
    widthOffset = "WidthOffset"
    heightOffset = "HeightOffset"
    precision = "Precision"
    seamAbberations = "Seam Abberations"

    amount = "Amount"
    probability = "Probability"

    seed = "Seed"

class Keywords:
    layerNumber = "layerNumber"

class BiasedCoin:
    def __init__(self, seed):
        self.randGenerator = Random()
        self.randGenerator.seed = seed

    def toss(self, headProb):
        weights = [100-headProb, headProb]
        return self.randGenerator.choices([0,1], weights=weights)[0]

    def uniform(self,a,b):
        return self.randGenerator.uniform(a,b)

Is my understanding of git revert wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

别再吹冷风 2025-02-10 17:49:23

您已经混淆了恢复并重置。您想要重置。您不会恢复提交,而是重置为提交。

由于您不想失去任何工作,所以要放一个分支来保留它;然后硬重置。因此,假设您的头在A342294,请说:

git branch failed-experiment 
git reset --hard 1bc90dd

You've confused revert and reset. You wanted reset. You don't revert to a commit, you reset to a commit.

Since you don't want to lose any work, make a branch to keep it; then reset hard. So, assuming your head is at a342294, say:

git branch failed-experiment 
git reset --hard 1bc90dd
愚人国度 2025-02-10 17:49:23

您无法将还原用作从历史记录中删除的工具。但是,如果您还没有推动它,则可以“修改”您的承诺。 (请参阅文档 - 从IDE或工具(例如Sourcetree或命令行)很简单)

如果您不想保留您的提交历史和反向动作的历史,那么最实用的方法是从上次正确的提交创建新的分支old_branch_delete和new_branch_rename。
见文档)

You can not use revert as tool to remove something from history. But you can "amend" your commit if you have not pushed it still. (See docs - it is simple from IDE or tool like Sourcetree or from command line)

If you do not want to keep history of your commit and your reverse actions, then most practical way is to create new branch from last correct commit and then do old_branch_delete and new_branch_rename.
See docs)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文