【问题标题】:reverting to an earlier commit and merging with the most recent commit in Git恢复到较早的提交并与 Git 中的最新提交合并
【发布时间】:2011-03-11 08:11:08
【问题描述】:

所以例如我有这样的历史:

commit 1a7cab6c279f5528871cd0ab8dae55319ff81fc0
Author: unknown <poru@.(none)>
Date:   Thu Mar 10 20:11:39 2011 +0800

    Changes to login style, will based the admin on this. version-1

commit 22d308ba085a5d04eadf54fd06f3534e876386de
Author: David Ang <davidang09@gmail.comm>
Date:   Tue Mar 8 23:40:59 2011 +0800

    fixed config settings to run in production mode and removed special
    characters thats disrupting heroku

commit 410b383e105fac39bd70095b186367fa943b1ad8
Author: David Ang <davidang09@gmail.comm>
Date:   Fri Mar 4 01:29:45 2011 +0800

     show pretty time ago
     provide icons
     hide mass delete
     removed special character

commit 789922463ad946c945893c9a8787e589f780fda1
Author: unknown <poru@.(none)>
Date:   Thu Mar 3 18:34:09 2011 +0800

     Tempory style for Login. Will replace this once done with the admin
     styles.

我们有一个新设计正在进行最近的提交 - 但我现在想切换回我们的原始设计,即提交 78992246。

我之前就想做这样的事情:

git checkout 78992246

然后我希望将这些合并回master的头上。

不幸的是,我没有到达任何地方

【问题讨论】:

  • 那么在你做了git checkout 78992246之后,你创建了更多的提交吗?

标签: git revert


【解决方案1】:

这里有一些步骤。

# Create a branch pointing to the original design and checkout to that branch.
git checkout -b original_design 78992246

# Work on it and commit your works on this branch.
git commit ...

# Once you're done, checkout your master branch.
git checkout master

# If you want to, pull from origin to update your master branch.
git pull

# Merge your original_design branch back to master.
git merge original_design

【讨论】:

  • 我已经这样做了。这是我的问题,第 2 步。我不想做任何更改,我只想签出旧设计,然后将其合并到主分支的头部。这样做 git 只会告诉我“已经更新”。
  • 顺便说一句,当我说我无法编辑这些文件时——我也指的是二进制文件——例如图像等,所以我只想将这些图像从我的旧设计中放到主人。
  • @David 你到底想做什么?您是要将所有内容还原为 78992246 还是仅还原部分文件?
【解决方案2】:

一旦你切换到正确的提交,你应该在尝试任何合并之前创建一个分支。

git checkout -b newdesign 

或一步完成

git checkout -b newdesign 78992246

否则,您将使用detached head mode

【讨论】:

    猜你喜欢
    • 2018-11-29
    • 1970-01-01
    • 1970-01-01
    • 2011-04-18
    • 2017-07-14
    • 2013-10-23
    • 2021-11-03
    • 2021-04-13
    • 2018-07-15
    相关资源
    最近更新 更多