user151841
user151841

Reputation: 18046

"replay" old commits over new ones

We have a website whose codebase we develop using git. When branches are merged into master, that goes to production.

We had a situation where we developed featureA and deployed it. Unfortunately, there were some problems in the deployment, and we had to roll the website back using the web-hosts on-board restore system.

This site is a Drupal website, and there are certain files that act as "config in code". Because of this, we export production's config files into a separate branch called prod-config.

So, after the restore, since production has changes in its configuration -- which is actually the pre-deploy settings, those changes show up as new commits in the prod-config branch.

This effectively undoes commits in the featureA branch that included updates to the config files. So now, the branch featureA is fully merged into master, but the changes to config files that I want to re-deploy are overwritten in new commits.

What is the "proper" way to re-play or re-do old commits that are effectively undone in newer commits?

Of course, I can just checkout the commit in the state that I want, copy the config files over, and commit those changes. But I wonder if there is a way using git commands to do what I need to do now.

Upvotes: 0

Views: 118

Answers (2)

Antoniossss
Antoniossss

Reputation: 32517

In comment you explained that you want make any particular commit HEAD?

To do this, you just have to RESET branch of your choice to that commit. This way, selected commit will become current branche's head.

git reset [--soft | --mixed [-N] | --hard | --merge | --keep] [-q] [<commit>]

After that you can push --force-with-lease to update remote branch.

More details here: https://git-scm.com/docs/git-reset

Upvotes: 0

oxr463
oxr463

Reputation: 1891

What is the "proper" way to re-play or re-do old commits that are effectively undone in newer commits?

One can use git checkout <commit> <filename>, to revert specific files from the previous commit, and then add the reverted configuration file in a new commit.

Upvotes: 1

Related Questions