2

We use WPEngine to host WordPress sites and push changes via Git to a staging version of the site - these can then be deployed to the production version via an internal script.

We staged the live site a few days ago and pushed up a number of changes via Git to the staged version.

Accidentally, one user pushed the button to recreate the staged version of the site and all our changes were lost - Git thinks that the local and remote are up-to-date - but of course, the staged version now shows the files in the form they are on the current live site.

Is there a way that we can force push up commits from the last x days or between two set hashes - or some other correct way to notify Git that the changes are no longer in sync?

Thanks!

Q Studio
  • 1,811
  • 3
  • 16
  • 18

2 Answers2

2

git push <remotename> <commit SHA>:<remotebranchname> should do the trick, provided <remotebranchname> already exists on the remote. If it doesn't, use git push <remotename> <commit SHA>:refs/heads/<remotebranchname>

Note that this pushes all commits up to and including the commit you choose. If you don't want that to happen, you should first use git rebase -i to re-order the commits.

Note: Picked this from thread on SO : git - pushing specific commit. Check it out for more details.

Community
  • 1
  • 1
  • Thanks - I had read that thread but running the command gives me "everything up-to-date" - so this does not resolve the problem – Q Studio Dec 27 '15 at 11:38
  • Running previous sha values other than the most recent tells me "tip of the current branch is behind.." – Q Studio Dec 27 '15 at 11:39
  • @QStudio That's strange. As I have followed this approach to push old commits again and it worked fine for me. Let me check. – Aaditya Gavandalkar Dec 27 '15 at 11:40
  • @QStudio Actually just wondering, can't you just perform a merge of the older branch on new master/staging branch so as to apply all the commits in the branch? – Aaditya Gavandalkar Dec 27 '15 at 11:42
  • When I pull from the staging it gives "already up to date"... It does not find anything to merge - how can I force this? – Q Studio Dec 27 '15 at 11:45
1

I have had a similar issue when I have had to restore a site from a backup on WP Engine. What works for me is to just change something in a file.

  1. Add a return at the end of any tracked file (any change at all will do)
  2. Commit change
  3. git push to remote

This should make sure everything matches local, adding/deleting/changing where needed, not just the last commit.

Nick Taylor
  • 161
  • 2
  • 13
  • This worked for me as well, but it seems so clunky. I have so many "dumb change to kick prod loose" commits :'( – allicarn Jun 03 '18 at 14:58
  • I agree. I feel like there should be a better way of doing it. Could be an issue with "bare" repositories since they don't keep branches? Not even sure that's what WP Engine is using. – Nick Taylor Jun 04 '18 at 16:01