0

I am working on git with another colleague and it seems like he erased all the changes I did in the repository in the last two weeks. When I check the history of the repository, the commits I did regarding 3 complete new files have disappeared.

I have now locally two repositories:

  • repo1: contains the original history of the repository because I did not pull the changes from origin. It contains the three files I created plus their history.
  • repo2: contains the latest version of the repository, i.e. nothing related to those 3 files

I checked this using "git log".

I have checked similar answers like in the following link: Restore deleted file with history in git

But the problem is that in repo2 the files don't have any existence. I tried to push the changes from repo1 into origin, but then I get issues and it doesn't seem to work.

Any ideas on how to fix this? Thanks in advance.

The branch is the master one.

jotNewie
  • 426
  • 4
  • 17
  • 2
    Talk to your colleague. There's plenty of things he can have done, for good and bad reasons, but you need to talk to him to learn about it. We cannot guess why he removed those files or commits or reverted them or whatever. He might not have meant to, but you won't know unless you talk to him. – Lasse V. Karlsen Sep 06 '19 at 11:12
  • He didn't mean to, and he cannot explain how it happened. He is new to git, and seems to be struggling with it... – jotNewie Sep 06 '19 at 11:25
  • 1
    My guess would be he did a force push. It might be enough to merge and push your commits back into the repository. – Lasse V. Karlsen Sep 06 '19 at 11:48
  • Can you give the name of the involved branch(es), and add to your question the error message you get when pushing from repo1 ? – LeGEC Sep 06 '19 at 12:14
  • Since I added my latest local version to the repository, now I cannot reproduce the error. I do have the files now, but without the history in the origin repository. I have added though the name of the branch: master – jotNewie Sep 06 '19 at 14:04
  • Use `reflog` in this machine and try to restore the state before the deletions. – m0skit0 Sep 06 '19 at 14:04
  • You all work on the same branch? You should consider creating your own branch and work there then rebase/merge, this way you won't have these problems as your local and origin branch will always have your work. – m0skit0 Sep 06 '19 at 14:05
  • 1
    Also, if you're new to git, you should disallow force push on the server, this will prevent strange losses of commits that nobody can explain. – Lasse V. Karlsen Sep 07 '19 at 11:34

0 Answers0