Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git remove remote history past certain commit

Tags:

git

gitlab

I have a Git/Gitlab repository. We used to commit straight to master, but we decided to switch to using feature branches like the rest of the world for this release.

We need to reset our remote master to the state it was in immediately after the last release. If someone has already committed to the master directly, how can I reset it to a clean state, removing all history past the last release?

I've spent about an hour googling now and can't find an answer to this specific question. Sorry if it seems redundant, it seems like such a simple task with no obvious answer!

like image 553
Jonathan S. Fisher Avatar asked Mar 26 '14 22:03

Jonathan S. Fisher


People also ask

How do I remove a specific commit from a remote?

To delete commits from remote, you can use the git reset command if your commits are consecutive from the top or an interactive rebase otherwise. After you delete the commits locally, push those changes to the remote using the git push command with the force option.

Can I checkout a previous commit?

To pull up a list of your commits and their associated hashes, you can run the git log command. To checkout a previous commit, you will use the Git checkout command followed by the commit hash you retrieved from your Git log.


1 Answers

To reset a local branch,

git branch -f master last-release

To reset a remote branch,

git push -f origin last-release:master

where last-release is the ref (commit id or branch) you want to reset master to.

(Neither of these affect your working tree; you can even do these from a bare repo, if you wish.)

like image 62
Paul Draper Avatar answered Oct 18 '22 15:10

Paul Draper