drzyeetvt41077335
drzyeetvt41077335
2015-11-10 21:11

为什么在其他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 dongwei4444 6年前

    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.

    点赞 评论 复制链接分享