jkgeyti
jkgeyti

Reputation: 2404

Git commit and push repository as-is (no merging) without destroying history

Say my repository is 2 commits behind origin, and I have yet to commit my changes.

I know those two remote commits are "garbage", and I want to commit and push my repository, exactly in the state it is now.

However, I want to do a clean "merge" that just ignores everything that's not as it is in my repository, i.e. deleting files not in my current directory, and ignoring any remote changes there might be. This way, it's clear to see which changes in the last two commits I've "reverted".

Essentially, I want to do a force push, without leaving the two commits I'm behind unreferenced.

How do I do that?

Upvotes: 0

Views: 87

Answers (3)

Alex Baker
Alex Baker

Reputation: 1627

If you're trying to do this without having revert commits in your history, you could stash your changes, pull remote, revert the two "garbage" commits, commit your changes from the stash, and then squash the revert commits into your commit.

Upvotes: 2

Anon
Anon

Reputation: 1

Pull the remote, reset the head to 2 commits ago, add your files, commit and push.

Upvotes: 0

Samuel Parkinson
Samuel Parkinson

Reputation: 3112

You could use git revert to undo the changes in those two commits, while still keeping track of them.

Catch up with the origin, revert the two commits, then commit your changes.

Upvotes: 1

Related Questions