0

Assume a non-version controlled project directory with sub-directories (A). A year later, that directory is COPIED and further development occurs (A').

I've just added the earlier version, A, to Git. In the spirit of version control I wish to copy A' files over A files (after all, they are the same project), but I seek to systematically delete A files that are no longer present in the later A' version.

I've Googled for quite some time but can't seem to find the best practice for this situation that (I bet) occurs frequently so I'm hoping there is a well-known "recipe" for how to pull it off without writing custom code.

Is it possible to use git-diff --diff-filter=D ("Deleted") to generate rm's so that the "residue" of A longer resides in source control?

Pete Alvin
  • 4,646
  • 9
  • 39
  • 56
  • Why are you trying to do this? What are you trying to preserve? How you answer will help me craft a better response. – JDB Oct 23 '17 at 18:12
  • @JDB Just want the initial and revised releases tracked as the same project under version control--just like any other software project. – Pete Alvin Oct 23 '17 at 19:19
  • Oh... yeah, there's no elegant way to do that. Sounds like you want to modify the history of your git commits. It's possible, but would be extremely messy and would be a huge problem for any ongoing work. You'd basically `git init` the directory with your `A` project, then add a commit. Then set your origin and fetch your master branch. Then you'd need to rebase master on the `A`. That will cause some minor catastrophes for anyone that has a branch based off master (including any dev or release branches you already have). – JDB Oct 23 '17 at 19:25
  • Oh... wait... is `A'` a git repo or is it just another directory with un-versioned code? – JDB Oct 23 '17 at 19:28

1 Answers1

1

So if A and A' are just two different directories with different version of code and you are creating a brand new git repo, then this is actually pretty easy.

Since you've already got your git repo setup with the A files, all you need to do is delete everything in your repo's directory (except, of course, for any git files/folders) and then copy the files from A', then add a new commit.

So, your git history would look something like this:

z9y8x7w6v current state (A')
a1b2c3d4e f1rst p0st (A)

You'll be able to compare changes between A and A', but any new work will be starting off with A'. This will just ensure that you have A as an old artifact in your git history.

Side Note: It's good that you are thinking about this now. If you had waited, and any work had been done off of A' in the repo, then slotting A into the history would have been extremely difficult.

JDB
  • 25,172
  • 5
  • 72
  • 123