3

I have, once again, explored the limits of stupidity. I have two directories, we'll call them D1 and D2. D1 is where I originally developed the application and where the git repository was set up. I also created a remote repository on github. When I changed IDE's, I copied D1 to a new directory, D2, and ported the project to Android Studio. Then, being an idiot, I proceeded to make lots of changes to the code in D2, to get the code to compile under Android Studio and run under Android Nougat.

Now, I have a bunch of files in D2 that are updated versions of the files in D1 and I want the repository to be updated and preferably move the repository to D2. I'm still fairly inexperienced with Git. How can I do this safely?

Additional Info 11/27/2017

The directory layout in D1 is for Eclipse/ADT, but the layout for D2 is Android Studio. The directory trees are different. So one of the ideas I was hoping would work, copying the git directories, won't. It looks like I'm going to have to try copying the source files, except then I still have the problem that when I do a clone, the directory structure won't be correct for Android Studio. Or am I completely missing something?

I did some more digging and found this post which means, I think, that it should be safe for me to move directories around in a repo.

Can Git restructure my folders without losing history?

Thanks for helping!

Rben
  • 489
  • 1
  • 7
  • 18
  • I'm still trying to come up with the right steps so that, in the end, I'll have the correct source under Android Studio and my git repository will be using that directory tree. – Rben Nov 27 '17 at 16:51

3 Answers3

1

Most obvious thing to do is copy the modified directories and files from D2 to D1. Git will pick up the changes and you can commit them. Although if you did a complete copy from D1 to D2, D2 is also likely a copy of your repo. You might be able to commit the changes from there.

If D2 isn't a repo, you could just copy the git directory, files, etc to D2 and git will have the info it needs. Or you could delete everything in D2 and reclone the project into it. The important thing is that your changes are in your repo, so you can check it out wherever you want.

JosephRT
  • 545
  • 4
  • 19
  • I'm going to try this. I'll comment after I've tried it. Thanks. – Rben Nov 26 '17 at 20:51
  • I looked at copying the git directories to D2, but D1 was built under Eclipse/ADT and D2 is Android Studio, so the file layout is different. This is going to be tougher than I thought. – Rben Nov 27 '17 at 16:35
  • Ooo, that's a different ball of wax. In that case, my suggestion is to upgrade D1 to Android Studio's project format first. If it messes up, you can revert back to a previous commit. After you've successfully upgraded your project (and committed right after the successful conversion) then move your directory/file changes over. I would definitely do this in steps: first, convert D1 to Android Studio, commit the successful conversion, and then move your changes over. – JosephRT Nov 27 '17 at 17:19
  • What I've actually decided to do is to start a new repo, since we've switched to the new IDE. We'll keep the old repo for historical stuff, and know it all works with Eclipse and the new repo will be for AndroidStudio. Still, this answer helped the most, so I'm checking it off. Thanks! – Rben Nov 27 '17 at 23:37
  • I found the real answer, I think. I can do a git clone -no-checkout which will create a repo in the D2 directory and then check in the modified files, no need for a new repo and all the history is preserved. – Rben Nov 28 '17 at 14:34
0

As I understand it:

  • D1 is a git repository

  • D2 is just a folder, having the updated files (which came from D1)

If you don't need the files in D1 anymore, wouldn't it be enough to just copy the whole content of D2 into D1 and commit/push the changes?

I wouldn't recommend creating a new repository for D2, because you won't see the previous changes then.

Before proceeding I suggest to backup both folders, just in case!

Al0x
  • 917
  • 2
  • 13
  • 30
0

The best way to do it (if you are working by yourself) is to backup that repository on Desktop and then delete it, after that you can safely make another repository and push D2 in the new repository. Although this may be time consuming but you can just copy the files from D2 to D1 that you added/modified and then proceed like nothing happened and git will render them as 'added' or modified (but of course if the file names are the same). You have two solutions. BUT PLEASE JUST FOR YOUR SAKE FIRST BACKUP THAT REPOSITORY.

nikjov92
  • 112
  • 9
  • 1
    I have 3 backups, two offsite. I'm paranoid about losing stuff. – Rben Nov 26 '17 at 20:48
  • 1
    You are not the only one. As I said you can just override files from D2 to D1 (and add the ones you added) and you will be set to go. If you approve any of our answers although they are the same can you just check them? Thanks. EDIT: I mean any of them. – nikjov92 Nov 26 '17 at 20:50
  • Check out the note I put in above. The differing directory structures are going to be a problem, aren't they? – Rben Nov 27 '17 at 16:41
  • Well the simplest thing you can do is make another repository and then just delete the old one. – nikjov92 Nov 28 '17 at 17:44
  • 1
    I wound up creating a new repository, but I'm keeping the old one for its history. I decided to create the new one because I was changing IDEs. – Rben Dec 08 '17 at 04:23