drzyeetvt41077335 2015-11-10 21:11
浏览 148
已采纳

为什么在其他2次提交之后git提交的更改会消失(我没有更改受影响的文件)?

What I did: I detached the head of my working branch MOODLE_27_STABLE. I then created a new branch called patterns new, checking out the detached head state with

checkout -b patterns_new

I then changed the file db/upgrade.php on 20th of october: Link to this commit, I call it A

Then, 2 commits later suddenly those changes disappeared in upgrade.php. But the commits do not mention, that db/upgrade.php was even modified.

After the first commit that followed, db/upgrade.php is still unchanged Link to that commit, B

Then after the next commit suddenly the db/upgrade.php file is overwritten with an older commit. [Link to that commit, C][3]

You can see in commit C, that nothing was changed viewing the diff. But in browsing the repository at this point in the history shows, that the commit A was overwritten with an older commit. (Near line 793 the additions made in commit A are not there anymore) [Link to the db/upgrade.php at that point in the history][4]

What I did to completely replace MOODLE_27_STABLE with the patterns_new branch (based on a detached head from MOODLE_27_STABLE was later that:

git checkout patterns_new
git merge -s ours MOODLE_27_STABLE
git checkout MOODLE_27_STABLE
git merge patterns_new

(based on the following tutorial [replace branch entirely by another branch][5])

I do now fear, that that might not be the only commit, that has been overwritten. Why can that happen and how can I assure, that all of the commits in pattern_new are "restored"? Should I cherry-pick them all again?

(I had to remove the links 3 to 5, because I am not allowed to post more due to a stackoverflow rule "You need at least 10 reputation to post more than 2 links)

  • 写回答

1条回答 默认 最新

  • dongwei4444 2015-11-10 21:54
    关注

    You've ended up creating commits based on patterns_new when you did not have the branch checked out.

    Which is fine, the commits are still there OK, but they're not on that branch. Your commit B, 303e50d, is the last commit on that unnamed branch and is the last one that has your change.

    Your commit C, 4835b67, has the original patterns_new commit, dbf4c2863, as its parent.

    Name a new branch on 303e50d and merge it with wherever your latest changes are and everything will be OK.

    Also, note that commits are never "overwritten" or changed in any way: they can't be - the hash wouldn't match! You can only ever add new commits or have commits without branches or tags garbage collected after a few weeks.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?