My team is working with git for the first time and has really messed up our git remote due to our inexperience. I’m trying to help educate them on git to solve the problem in the long term, but in the meantime, the commits that have been made are totally wrong. We haven’t made very much progress at all, and I don’t see the value in retaining these commits when they could cause confusion/additional problems down the line.
The most recent commit was a merge between the master branch and a second branch that one of the team members unintentionally created. If I try to revert, git states that I must be using the -m flag, but I’m not sure whether I should be reverting or trying to rebase in this case, or how I would do it given the structure of the past couple of commits.
What is the best way to resolve this issue and how should I go about doing it?
5
To undo the merge, you can do
git checkout master
git revert -m 1 [SHA of the merge commit]
git push
This will create and push a new commit which reverts all changes that were merged in.
It’s also possible to alter master’s history so that it appears as if the merge never happened, but I wouldn’t recommend it. Your teammates would have trouble when they try to pull master and the history is different. Also it’s easy to revert a revert commit if you reverted the wrong changes, but if you alter mater’s history, it’s harder to undo that.
6
I believe you’re looking for the git reset command. If you run git log it will show you a commit history for your repo. Then run git reset –hard HEAD-number of commits you’d like to go back.
Documentation here: http://git-scm.com/docs/git-reset
11