0

In my development environment, my media/static files are slightly different to server environment. Different enough that if they are pushed live, it breaks my app.

I pushed them live by mistake - originally it pulled the server statics to my local environment. I fixed this.

Now I am trying to fix the server side, and here's where Git (to me at least) seems so....frustrating.

I can go on my server and type git checkout HASH. The hash returns me to the particular commit before I broke things. Great. My server is now back to where I'd like it.

What I'd now like to do, is keep it that way.

So I type:

> git checkout -b tmp
> git branch
..first
..master
..tmp
> git checkout tmp

If I now load my web app, the code isn't up to date (expected) but the big problem of all my static media files being deleted has gone away. Great. I have reverted my change. Now I want to merge that with my master...? I think?

git checkout master

Reload my webapp - it's now broken because of missing static media.

git merge tmp
..Already up to date

I reload the page - it's still broken. I've not reverted anything... ?

git checkout tmp

The page is working again.

How do I fix this? I have changes in my remote 'origin' repo which I'd like to merge with the app, but before I can do that I need to revert the deleted static files permanently. What do to?

phil0s0pher
  • 525
  • 10
  • 21
  • Your `tmp` branch was already merged into `master`, so changes there are already incorporated into master, which means merging again won't work. What you need to do is revert the change. See https://stackoverflow.com/questions/4114095/how-to-revert-a-git-repository-to-a-previous-commit and many other questions about reverting a branch to a previous state. Basically, you'll need to make a new commit that brings your branch back where you want it, and commit that on top. – joanis May 13 '19 at 14:55
  • Alternatively, if you are allowed to do this, use a forced push: `git checkout master`, `git reset --hard `, `git push -f`. That's also discussed in the link I posted. – joanis May 13 '19 at 14:56
  • Possible duplicate of [How to revert a Git repository to a previous commit](https://stackoverflow.com/questions/4114095/how-to-revert-a-git-repository-to-a-previous-commit) – joanis May 13 '19 at 14:58

0 Answers0