0

I have a project in a repository.

A programmer (not Me) changed the deployed code on the server directly instead of editing the Git controlled repository (a lot of changes have been made).
So now the repository has an old version of code.

What should I do in this case?

Should I create a new empty branch, copy the code from server there and then make this branch master like it's described here?
Or something else?

Community
  • 1
  • 1
Heidel
  • 3,174
  • 16
  • 52
  • 84
  • Does the server contain a working or a bare copy ? – Claudio Mar 24 '16 at 14:10
  • 2
    What's your end goal? Do you want the code the programmer changed in the repository? or revert to the repository version? or save the changes the programmer made but still revert to the repository version? – Harmelodic Mar 24 '16 at 14:11
  • server contains working code, so I want the code from server to become a new version. – Heidel Mar 24 '16 at 14:12

1 Answers1

1

I think the first priority is to get that code into git. I would treat the code that's in production as new development work.

  • Create a new branch off of your current master / development branch. Assuming your server is a checkout of the master branch:
    • git checkout -b prod-edits origin/master
  • Commit the production edits into that branch just like typical code changes.
    • git add -A
    • git commit -m "Production edits"
    • git push origin prod-edits
  • Then I would go through whatever workflow you normally do for feature branches, e.g. merge into a test branch, QA it, merge into master.
  • Next step is launching. If you launch "by hand" by pulling down master directly onto the server, I would remove the edits and download the latest. This is the destructive step that will change your code in production, so do this in a copy of the directory and symlink back to it after it's complete. Have a backup ready. Something like
    • cp -r /path/to/code /path/to/current
    • cd /path/to/current
    • git reset --hard && git pull
    • rm -fr /path/to/code && ln -s /path/to/current /path/to/code
Matt S
  • 14,976
  • 6
  • 57
  • 76
  • Could you explain me please which commands I should use to save all code from server to new branch? `git add .`, `git commit -m "comment here"`, `git push origin new_branch`, is that right? – Heidel Mar 24 '16 at 14:47
  • What command `git checkout -b prod-edits origin/master` does? I'm really afraid to break something, because I have full the newest version code only on server. – Heidel Mar 24 '16 at 15:02
  • Sure, it's scary! None of these commands change the code or move any files. `checkout -b` starts a new branch in git tracking against master. `add` and `commit` get the edits into the git branch. `push` moves them to the server. No code will change in production until you re-release your branch (I'll add more commands). – Matt S Mar 24 '16 at 15:09
  • `Then I would go through whatever workflow you normally do for feature branches, e.g. merge into a test branch, QA it, merge into master.` but when I do merge, it would change code on my server, right? – Heidel Mar 25 '16 at 08:54
  • Once you get the code into git and your remote repo (steps 1 and 2), perform the merges and any code fixes on your local computer. The code on the server only changes with the last steps (`reset --hard` and `git pull`). – Matt S Mar 27 '16 at 14:44