4

I have a project I'm working on which I've set up in a git repo.

Since I put my latest version live, the website owner has made some changes to the working/content by overwriting it directly.

Obviously these changes were made outside of version control. I suppose I could overwrite the entire contents of my repo, then commit. That should work... but I don't really like the idea of doing that, especially if there's been any replacement of correct code/html-structure with stuff that's incorrect or bad practice.

What I'd like to do is dump the website from live into another directory and do a recursive diff so I can only overwrite those files which have changed (any correct any issues if there are any)

Tom Busby
  • 1,319
  • 2
  • 12
  • 25

3 Answers3

5

As in if I just overwrite what's in my git repo, then run git status?

No, you don't have to overwrite anything.

You can do a diff between:

  • the index representing your site in its latest versioned state (in the git repo)
  • a dump of the current live site (a copy done in a different folder, not under version control)

You can then do (using git options) a:

git diff --git-dir=/path/to/repo/.git --work-tree=/path/to/dump .

You actually can execute that command from any folder: it will look for the git index and for the right working tree.


The OP Tom Busby adds in the comments:

In the end I solved it by simply overwriting the .git folder in my dump directory with the one from my git repo and running git diff.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I'm getting this error: Not a git repository To compare two paths outside a working tree: usage: git diff [--no-index] – Tom Busby May 24 '14 at 22:32
  • 1
    @TomBusby That is because you didn't pass the `.git` folder path of your repo: `--git-dir` must reference the `/path/to/your/repo/.git` (the `/.git` at the end is important) – VonC May 25 '14 at 06:07
  • Still having the same problem: git diff --git-dir=/home/tom/Git/vikingchallenge/.git --work-tree=/home/tom/Git/www/.git . Not a git repository To compare two paths outside a working tree: usage: git diff [--no-index] – Tom Busby Jun 02 '14 at 13:10
  • Tried it with and without the /.git on the end of www – Tom Busby Jun 02 '14 at 13:10
  • @Tom The work tree must not have the .git, only git-dir ends with .git. And make sure both paths exist. – VonC Jun 02 '14 at 13:20
  • @tom that is what I meant by "make sure both paths exist": if you delete folders, I confirm that won't work well... – VonC Jun 02 '14 at 13:23
  • @Tom and the /path/to/repo I mention in my answer must be a path to a git repo. – VonC Jun 02 '14 at 13:24
  • You just said the work tree must not have a .git. I just got rid of it and it still doesn't work, the paths exist. /path/to/repo is a git repo – Tom Busby Jun 02 '14 at 13:25
  • I've tried absolute paths, relative paths. I've tried pwd outside of both dirs mentioned, and I've tried it inside the repo, and inside the work tree. Same error every time ----- Path to repo is a git repo, path to dump isn't. – Tom Busby Jun 02 '14 at 13:32
  • @TomBusby the idea is: you specify a git repo (`/path/to/repo/.git`), and a place where you have that repo content (`/path/to/dump`, no `.git` at all): you can then compare both. Both paths are absolute. But both paths are *different* paths. – VonC Jun 02 '14 at 13:58
  • tried that, it didn't work. In the end I solved it by simply overwriting the .git folder in my dump directory with the one from my git repo and running git diff. – Tom Busby Jun 02 '14 at 14:23
  • @TomBusby Ok, I have included your conclusion in the answer for more visibility. – VonC Jun 02 '14 at 14:26
  • But yeah man, sorry, I'm going to have to untick it. I've followed your instructions, and tried every permutation I can think of to make it work and it doesn't work. I do appreciate the help, it's just if someone else comes along, it shouldn't be ticked as if it works. – Tom Busby Jun 02 '14 at 14:26
  • @TomBusby that is why I also have included your conclusion. To avoid unticking ;) – VonC Jun 02 '14 at 14:27
2

VonC's answer is excellent, but I believe you could also just use the diff command (a built-in command on most operating systems). This would also ensure that "gitignored" files were diffed (though VonC's might already do that).

Assuming the website in /www/mysite and a fresh clone in /git/mysite you could just do:

diff /www/mysite /git/mysite

brock
  • 2,302
  • 7
  • 27
  • 30
-1

Yes We can compare two directories very easily

simply using this command on Shell/Terminal

git diffdir any-branch-name any-other-branch-name

Nazia Sadiq
  • 41
  • 1
  • 10