How can a file be changed in Git / Github without commit

综合技术 2018-07-14

We have a situation where sometimes a file in github reverts to a previous version. We only have a master branch. We can see the change in the commit history, and it is the last change that has occurred for that file, but viewing the file in Github and pull / fetch from client tools shows an older version.

One possible symptom is that normally I see this when viewing each commit at the repository level

Commit Parent
2 1
3 2
4 3
5 4

However, in the case where the file has lost its changes, it looks like this:

Commit Parent
2 1
3 2
4 2
5 4

And the change made in commit 3 has gone.

So here is what I bet is happening here: either commit 5 has both 3 and 4 as parents (i.e. it is a merge commit), or some descendant of commit 5 is a merge commit, with one of its parents being commit 3. If that is the case, here is what happened: commits 1 and 2 were both on the server and in everyone's local repositories. Someone makes commit 3 and pushes to the server. Someone else (without pulling from the server) makes commits 4 and 5 (and perhaps more). If they try to push, they get a "no fast forward" error, since their repo is out of date. The error suggests that they pull, so they do just that. Now a pull is a fetch and a merge, but in this case, the merge resulted in conflicts, so it was not automatically committed. The person resolves the merge conflicts, but then before committing the merge notices that there are changes (totally unrelated to the conflicts) staged that they did not make. These are the changes from commit 3 that are about to be lost. The person undoes those changes, commits, then pushes.

The reason why you do not see this "botched merge" commit when you view a history of the file in question is that git by default does not include merge commits in a file's history if that file is not different than both
of that commit's parents. In this case, the file is different than commit 3 (because the changes done in commit 3 were undone), but is not different from the other parent. To include this botched merge in the history, use git log --full-history
.

The bottom line is that all users of the repository must be made aware that when committing a merge, they must
commit all staged changes, even if they did not make those changes, as those are the changes that are supposed to be merged in from the "other" branch.

Hello, buddy!

责编内容by:Hello, buddy! (源链)。感谢您的支持!

您可能感兴趣的

Python模拟Github登陆 Python模拟Github登陆,详情请查看源码点链接进入 Python-Spiders文集 ,模拟Github登陆可以分为五个操作步骤,步骤如下: 模...
Playing with a Bela (2): Compile last Audio Toolki... More than a year ago, I started playing with theBela board. At the time, I had ...
使用 Python3 编写 Github 自动周报生成器(二)... 实战:编写周报生成器 一、实验简介 1.1 实验内容 很多项目是依托于 Github 平台进行需求发布、开发管理、多人协助的。如果你主管某个项...
How Often do you Commit? Received an email today where I thought I would post my answer: Hey Howard...
GIT for the Scared Java Dev: Trusting Your IDE One of the main issues some developers have when it comes to Git is trusting the...