1

I'm trying to get a git repository from a production server.

  • The code was deployed using OpenShift.
  • The latest commit in production does not appear in the repository that I have.
  • It was deployed by the previous person who worked on the project. This person doesn't know where the code came from.

I was able to find:

  • The code under /var/lib/openshort/.../app-deployments/current/repo.
  • The latest commit using git log under /var/lib/openshift/.../git/my_proj.git

(checkout the OpenShift Filesystem overview)

How can I git push the code from production into my git repository?

Michael
  • 3,206
  • 5
  • 26
  • 44
  • I have seen your edit (and https://developers.openshift.com/en/managing-filesystem.html#git): `git contains the application source code. It is simply named after the application. You do not usually need to care about this directory.` I suppose you cannot clone/pull out of that folder? – VonC Jan 31 '16 at 14:06

2 Answers2

1

Getting from means git pull or fetch, not git push.

If git pull is not enough, try and check if you see that commit (as fetched) in your local repo (since git pull would already have done git fetch as part of the sequence "git fetch + git merge")

git log --oneline --decorate --graph --all

If it is not possible to pull directly from the Openshift server, it is still possible to bundle the bare repo /var/lib/openshift/.../git/my_proj.git into one file with git bundle.
That file can be copied over, and cloned as a regular repo.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Usually `git pull` would be used to get code *from* a server. But in this specific case, I am not able to find the repository of the code that is on production. Anyway, the result of `git log --oneline --decorate --graph --all | grep 0c8e12` is empty. – Michael Jan 31 '16 at 11:44
  • @Michael If you have found the right commit on that production server, why can you not pull from it? Or at least clone it, and validate you do see that commit on your new local clone? – VonC Jan 31 '16 at 13:46
  • Because the deployment was done using OpenShift, that means, that while I'm in the code root `/var/lib/openshort/.../app-deployments/current/repo` and I type `git status` I get an error that this is not a git repository. This question is more oriented to OpenShift experts who can explain how to perform "class" git operations on production. – Michael Jan 31 '16 at 13:53
  • @Michael I thought it was a git repo because you typed "The latest commit using `git log` under `/var/lib/openshift/.../git/my_proj.git`": were you talking about your local repo? And is that latest commit the one you seek or not? – VonC Jan 31 '16 at 14:00
  • @Michael I mean, if the Openshit doc (https://developers.openshift.com/en/managing-modifying-applications.html#using-git-repository) says "Every OpenShift application you create has its own Git repository that only you can access", there must be a git repo on that server, no? – VonC Jan 31 '16 at 14:03
  • I agree, I just wonder where that repository is. Under `/var/lib/openshift/.../git/my_proj.git` the command `git log` works and no other git command works. The code itself is under `/var/lib/openshort/.../app-deployments/current/repo` where no git command works. That is the reason why I feel like there is a need for OpenShift (or git) expert. – Michael Jan 31 '16 at 14:06
  • Do you see the right commit (the one you seek) under `/var/lib/openshift/.../git/my_proj.git`? Can you pull from that repo? – VonC Jan 31 '16 at 14:08
  • @Michael `current/repo` is probably a checkout of that `my_proj.git` repo: you can do a `git --git-dir=/var/lib/openshift/.../git/my_proj.git status` – VonC Jan 31 '16 at 14:09
  • I want the commit that I see under `/var/lib/openshift/.../git/my_proj.git` because I guess that it is the latest deployment. No git command that I have tried other than `git log` seems to work under `/var/lib/openshift/.../git/my_proj.git`. – Michael Jan 31 '16 at 14:10
  • running `git --git-dir=/var/lib/openshift/.../git/my_proj.git status` gives `fatal: This operation must be run in a work tree` – Michael Jan 31 '16 at 14:12
  • @Michael are you running it under the `current/repo` folder? – VonC Jan 31 '16 at 14:25
  • 1
    @Michael I get it: my_proj.git is a bare repo. Try `git -c 'core.bare=false --git-dir=/var/lib/openshift/.../git/my_proj.git status` – VonC Jan 31 '16 at 14:28
  • Sounds like you are correct. `-c` is not supported in this git version (1.7.1) I was not able to find `-c` in `man git`), and since it's a production server I tend not to upgrade git. Any idea? – Michael Jan 31 '16 at 15:17
  • 1
    @Michael Yes, git bundle: http://stackoverflow.com/a/2545784/6309. Export the bare git repo that way in one file. – VonC Jan 31 '16 at 16:13
1

It was a bare repository, and as @VonC recommended, I bundled it. Its commits were very different from my repository. God knows what kind of magic OpenShift spelled on it.

I just plain copied the entire repository.

Michael
  • 3,206
  • 5
  • 26
  • 44
  • 1
    Probably some kind of git filter-branch or other rebase operation that has changed the history of the repo. Good feedback. +1 – VonC Jan 31 '16 at 19:06