3

For the sake of an example, supose I have an old copy of phpMyAdmin (not under revision control) in my home directory. I would like to upgrade it to the latest version from the "stable" branch.

So basically, I just want to be able to do

git pull

and have my copy of phpMyAdmin "upgraded" to the latest version.

Is that possible? I assume I would need to put phpMyAdmin under revision control first.

Thank you!

Maxim Neaga
  • 921
  • 3
  • 17
  • 29
  • 1
    What's the reason you don't just delete your old copy of phpMyAdmin and clone the repository from scratch? Is there anything there you want to keep? – tobiasvl Feb 28 '14 at 18:45
  • 2
    possible duplicate of [How can I associate local unversioned code to git remote repository?](http://stackoverflow.com/questions/13052172/how-can-i-associate-local-unversioned-code-to-git-remote-repository) – pattivacek Feb 28 '14 at 18:53
  • @tobiasvl - there are some files in the directory that were created (none were modified though). phpMyAdmin is just for an example. So if I completely delete the directory, those files will be lost. – Maxim Neaga Feb 28 '14 at 18:53
  • 1
    Okay. I'm sure there's a way to do it (see the possible duplicate) because git is all-powerful, but I'd just clone the remote repo into a different directory, `git checkout` the revision that corresponds to the old version you have locally, and then either just do a `diff -r clone old` or move the `.git` subdirectory over to your old copy or something. – tobiasvl Feb 28 '14 at 18:57

2 Answers2

5

If you need to keep your existing code, then get yourself a Git repository with:

cd <dir>; git init; git add --all .; git commit -m 'Initial commit'

and then add the remote and pull (master->master)

git remote add origin <path-to-remote>;
git pull origin master

If you don't need your existing code base (which doesn't sound like what you are asking but):

git clone <path-to-remote> <into-some-dir>

then you can use diff tools on the two directories (original and newly cloned).

GoZoner
  • 67,920
  • 20
  • 95
  • 145
3

You don't need to include your local unrevisioned code to version control

You can clone the repo to your local with

git checkout

and then do a

diff -b path-to-cloned-repo path-to-unrevisioned-local-repo > difference.patch

then apply this patch to your cloned repo:

patch -p1 < difference.patch

You can test your patch before applying by:

patch -p1 --dry-run < difference.patch
David G
  • 94,763
  • 41
  • 167
  • 253
brokenfoot
  • 11,083
  • 10
  • 59
  • 80