The Case of the Missing Commits: A Git Mishap and Lessons Learned

 > Tech >  The Case of the Missing Commits: A Git Mishap and Lessons Learned
0 Comments
The Case of the Missing Commits: A Git Mishap and Lessons Learned

I want to share a rare and amusing incident that happened recently. My colleague Khizer Najeeb and I worked on a frontend module on separate branches derived from the master branch.

Once I completed my work, I pushed the code into the master branch after a thorough review and initiated the deployment. Everything seemed to be functioning perfectly.

Khizer, who was working on the same project, updated his branch from the master and merged his code back into the master branch. He then initiated a deployment from the master branch, and suddenly, an unfortunate event occurred: all my work and commits had vanished from Git.

I asked Khizer if he had used the –force command to push his code, but he assured me he hadn’t. I trust him completely, as he is one of the best frontend engineers in our office.

The dilemma was that my branch contained my work and a few files from Khizer, while Khizer’s branch had his work without my changes. If I were to merge my branch back into the master, it would override Khizer’s code.

After spending an hour trying to resolve the issue, I sought help from my colleagues Mohammad Urwah and Muhammad Zuhair Waheed. Both worked diligently to retrieve the missing code and eventually, we discovered that all my work was in a commit that wasn’t associated with any branch (I don’t know why it happened).

After some intense troubleshooting, we managed to retrieve my work from that commit. During this process, I also learned a few tricks about the VS Code timeline feature, which isn’t dependent on Git and saves your work history independently.

Ammar Rizvi bhai gave me invaluable advice to always practice Trunk-Based Development (TBD) to prevent such issues in the future.

Thank you so much, Urwah, Zuhair, and Khizer, for your assistance and support.