1

First off, I must mention... I am a complete newbie to Git, and how to use it. So bare with my lack of understanding here.

So, recently we had a 3rd party developer who was making a whole bunch of customizations on our soon to be live website, basically disappear from us. They had been using Git. However, just before they went offline, they transferred the Git Repo to me. Until that time, I had never used Git. Due to time constraints, I took it upon myself to complete most of the final changes needed on our website, directly on the server taking actual backups along the way. At one point, I tried to sync the server back to master, but I got denied because I could potentially over-right some files. I tried reading some thread, and sadly, I ended up running a hard reset on my Git. I tried a restore, but that doesn't seem to have reset my git situation.

Now, I want to take ALL the changes that have been completed on the SERVER, and start a new Git master Repo. I'm ok, with wiping any branches that previously existed, but I have no idea how to link the server to a new Git repo (that I just created in bitbucket), and push all of the required content to the new repo. I'm afraid of getting these sequences wrong, as I don't want to have to "start over" (albeit, I have a full magento 2 backup of my server, taken an hour or so ago).

The repo's are being hosted on Bitbucket if that makes any difference.

I do have a local install of Sourcetree, but I have no idea how to really use it properly.

As for the old repo, I won't delete it, and I have a copy of the master/origin repo in my SourceTree (that I'll likely zip and then remove completely once this is done).

Once, I have the master updated, I'll want to deploy this to another backup/dev server, that was again previously sync'd to the old git.

any and all help is appreciated.

  • Your question is very confusing. I see three major players in your problem: the work done by the contractor, your current local branch,and what is on the repository. Update your question by telling us which information is where, and what you want to have happen. – Tim Biegeleisen Dec 01 '16 at 01:59
  • Possible duplicate of [How to undo last commit(s) in Git?](http://stackoverflow.com/questions/927358/how-to-undo-last-commits-in-git) – AAM111 Dec 01 '16 at 02:44

1 Answers1

0

It's one of the only times I can think where using "git reset --soft" makes sense!

On the server here's what I would do. There are a number of assumptions here:

  1. You might as well push the contractor's repo to bitbucket using "cd /path/to/repo; git push --mirror [bitbucket-url], and base the rest of this on that.
  2. Assumes you have backups of everything.
  3. These steps also assume the directory layout on the production server is identical to the layout in the repo, aside from any directories you had to move or add or rename.
  4. Finally, these assume 'master' is the name of the bitbucket branch you want to sync back to.

(Oh, and choose whatever plain text editor you prefer for the "edit .gitignore" step).

If the assumptions hold, here is the sequence of commands I would use to sync your production server back to your master branch:

cd /path/to/code/on/server
touch .gitignore
edit .gitignore         # set dir and file patterns you want to omit
git init                # init is safe even if git repo already present
git remote add origin [bitbucket-url]
git fetch

# The "soft" reset!  Makes git think your work on the server
# directly followed from latest commit on 'master':
git reset --soft origin/master

git add .               # adds all files from all sub-directories
git status              # do things look reasonable?
git diff origin/master  # should see all of your work in "patch" format

# If everything looks good, do the commit!
git commit -m 'sync prod back to bitbucket'

# And send your commit to bitbucket!
git push origin HEAD:refs/heads/master

One Warning: be careful what you add to the .gitignore file. Any files or directories that match the patterns in that file will be completely ignored by git, and not synced back to your bitbucket repo.

G. Sylvie Davies
  • 5,049
  • 3
  • 21
  • 30