monkeyman
monkeyman

Reputation: 67

Git deleting unwanted commits

Image from gitk

I'm new to a project (and to collaborative Git), and have managed to get myself in a bit of a tangle. I have been creating pull requests, and branches off of those to commit to, then pushing them to back to the remote, but unwittingly detached the HEAD which has resulted in the image below.

What I'd like to know is:

Is it possible to get rid to get rid of the commits from the point of divergence along the green line and;

How to remove the second long straight pink line?

Or if both of those options are impractical, just some good advice on how to tidy this up!

Upvotes: 2

Views: 179

Answers (1)

hspandher
hspandher

Reputation: 16733

Just change you HEAD, that should do the job as far as your needs are concerned.

git reset --hard <commit_id>

Here commit_id is the commit hash till you want to reset your changes. You can find commit id using gitk or git log --oneline command.

Now, this holds true, when you haven't pushed those changes if you have then you might have to force push to the branch.

git push -f origin/<branch_name>

Note: Tread carefully since this might lead to loss of commits of some other user.

Upvotes: 2

Related Questions