How I Got Out of a Knee Deep Git Problem
How I Got Out of a Knee Deep Git Problem
Problem
- I am not used to rebasing or squashing commits, my new project strictly follows this hence I was pushed to do this.
- I started with 4 commits which I had to squash
-
git rebase -i HEAD~4
and squashed all the commits all were good
- But, as I pushed the code there was a conflict with the master
- If you remember you cannot
merge
hence I did a git rebase -i master
- Now I ended up having 10 more commits from god knows where
- I cannot push all of them, hence I squashed them all again, in spite of the commits not being mine
- I pushed my code, but the conflict was still there, at the brink of frustration I fixed the conflict in Github and left it there
- As expected, I was asked not to merge from master and revert it
- Now I am knee stuck with a merge, 9 commits squashed within which another 4 commits squashed
Solution - Git Reflog to the rescue
-
git reflog
has a history of all the commands you ever executed
- On running it I found the first squash I made
-
git reset --hard <commit_id>
took me to that commit
- One mistake I did last time when I rebased master was I didn't rebase from upstream so this time I ran
git pull upstream master --rebase
- Now I did a
git add .
to add my changes to rebase
-
git rebase --continue
finishes the rebase successfully
- Finally
git push origin --force <branch-name>
to push the final version with no-conflicts and just my commits squashed into one.
Once suspended, bhavaniravi will not be able to comment or publish posts until their suspension is removed.
Once unsuspended, bhavaniravi will be able to comment and publish posts again.
Once unpublished, all posts by bhavaniravi will become hidden and only accessible to themselves.
If bhavaniravi is not suspended, they can still re-publish their posts from their dashboard.
Once unpublished, this post will become invisible to the public and only accessible to Bhavani Ravi.
They can still re-publish the post if they are not suspended.
Thanks for keeping DEV Community safe. Here is what you can do to flag bhavaniravi:
Unflagging bhavaniravi will restore default visibility to their posts.
Top comments (2)
Squashing via
git rebase
is hard. Do it in easy mode instead:If there are conflicts, resolve them and
git commit
to complete the merge. Then:Good to note