I work in a small company and our Git repo is a little messed up. I just did a git pull
and my changes made earlier today are gone!
When I work on HEAD on the master branch, git log
shows my last commit b94940c63ef965ce45b0d64ccfba4359134d2552 in its history.
Now if I do git log filename
for the problematic file that lost my changes, that commit is not shown (only shows an earlier commit).
Performing git log --follow filename
, my commit b94940c63ef965ce45b0d64ccfba4359134d2552 is shown as most recent.
And sure enough if I do:
git checkout b94940c63ef965ce45b0d64ccfba4359134d2552
git log filename
then the commit is shown and my changes are in the file!
In other words, the commit I made is shown in the branch history (blocking a branch merge), but individual modified files do not have that commit in their history! (unless I explicitly checkout that commit).
Questions:
How on earth did this happen?
How do I fix it? (We have problems with multiple files in our repo)
Git stores the complete history of your files for a project in a special directory (a.k.a. a folder) called a repository, or repo. This repo is usually in a hidden folder called . git sitting next to your files.
No, git rm will only remove the file from the working directory and add that removal into the index. So only future commits are affected. All previous commits stay the same and the history will actually show when you removed the file from the repository.
On GitHub, you can see the commit history of a repository by: Navigating directly to the commits page of a repository. Clicking on a file, then clicking History, to get to the commit history for a specific file.
Alright figured out the problem. When a coworker pulled, he got some conflicts. Rather than resolving, he git reset every staged file. This was akin to doing a git checkout old_version on individual old files. So HEAD on the master ended up referring to some files that had old_version.
Now I'm manually restoring what he blew out.
Moral of story: Modifying git operations (checkout, reset, etc.) on individual files are quite dangerous.
This should be just a comment, but it would be hard to read. After checking out master:
git checkout master
what's the output of
git status
and
git whatchanged -m -p <path>
and
git log --graph --oneline b94940c63ef965ce45b0d64ccfba4359134d2552..master
?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With