我该如何“解耦"?我的旧Eclipse repro是我的新android studio repro? [英] How do I "decouple" my new android studio repro from my old eclipse repro?

查看:84
本文介绍了我该如何“解耦"?我的旧Eclipse repro是我的新android studio repro?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新

我要解决的这个问题是要完成我的eclipse项目到Android Studio的迁移,并保留所有文件历史记录.我什么时候开始我从eclipse项目的克隆开始的路径,但是遇到了以下问题.我从eclipse repro的副本而不是克隆的副本开始进行了重新设计,并设法获得了我想要的(请参阅下面的答案)

原始问题:

我将eclipse项目迁移到了android studio.为了保留git历史记录,我将现有的eclipse存储库克隆到了一个临时空间/tmp/git_rename中(例如)

在该克隆的副本中,我执行了以下操作:

  1. 删除了Android Studio中不需要的所有文件(例如,项目设置)
  2. 将源目录和资源目录移动到了它们在android studio中的位置 (例如,我将src的内容移至app/src/main/java)

我通过创建一些新分支来做到这一点.像我一样将它们提交并合并回master.

然后我有了一个git repo,它在迁移的android studio项目中的源文件中的源文件位于相同的位置

然后我将此.git目录复制到我的android studio目录的根目录中

我认为这满足了我的大部分要求(我可以看到我所有Java和资源文件的历史记录.)

问题在于,由于我做了克隆,所以所有旧分支只是对旧Eclipse存储库的引用,如下所示.我真的希望这是一个"standslone"存储库,其中所有旧分支都在其本地提交.我也有一个本地主机和一个远程主机的问题.然后,我会将其推送到某个远程进行备份.

我想这应该很容易做到,但是我很接近我想要的东西,而且我真的不想破坏任何东西.


有人可以给我一些指导,说明如何从我的位置(如下所示)转到具有所有本地分支机构和一个主管的单个回购协议吗?

解决方案

我上次从头开始进行此操作.我将记录我所做的事情,希望它将帮助其他人找到将Eclipse ADT项目迁移到Android Studio并维护所有git历史记录的好方法(这对我来说并不明显).

这假定您已经通过了迁移向导,并且已经迁移了您应用的Android Studio版本,但是现在您也希望将所有git历史记录也移过来. 如果您还没有这样做,那是相当困难的事情,您可以从

  • 进行最后检查,这时您应该只拥有包含要保留其历史记录的文件的目录和.git目录,而没有别的.

  • 使用git提交这些更改,将其合并到master中,并创建(并切换到)最后一个新的分支,该分支名为files_added_by_android_studio

  • 使用cp -rp复制(这很重要) .git目录到您的android studio项目根目录中.请注意,您对迁移的android studio项目所做的唯一更改是将.git目录复制到其中.

  • 使用下面显示的内容在android项目目录的根目录和app子目录中创建或更新您的.gitignore文件.

  • 在您的android studio项目的根目录中,使用git gui(或git status)来确认只有一堆充满新文件

  • 提交并合并到母版中

  • 启动android studio并启用版本控制集成(在主菜单栏上的VCS下)

  • 应该这样做.听起来比实际要复杂得多.基本上,您正在复制现有的.git文件夹,对其进行修改,以便它希望看到更改将在android studio中发生,而不是在eclipse中发生,然后将修改后的.git文件夹复制到您的android studio项目中. /p>

    这是我使用的两个.gitignore文件:

    在项目根目录中.

    .gradle
    /local.properties
    /.idea/workspace.xml
    /.idea/libraries
    .DS_Store
    /build
    

    在应用文件夹中:

    /build
    

    Update

    My intent with this question was to complete the migration of my eclipse project to Android Studio and keep all the file history. I when to a path where I started with a clone of the eclipse project , but ran into the following issue. I reworked this starting with a copy of the eclipse repro rather than a clone and managed to get exactly what I wanted (see my answer below)

    Original question:

    I migrated my eclipse project to android studio. In an attempt to retain the git history, I cloned the existing eclipse repo into a temp space /tmp/git_rename (for example)

    In that cloned repro I did the following:

    1. removed any files that would not be needed in Android studio (projects setting for example)
    2. moved the source and resource directories to the locations they would be in android studio (for example I moved the contents of src to app/src/main/java)

    I did this by creating a few new branches. committing and merging them back into master as I did it.

    What I then had was a git repo that had the source files in the same locations at the source files in the migrated android studio project

    I then copied this .git directory in the the root of my android studio directory

    I think this did most of what I wanted (I can see the history of all my java and resource files).

    The problem is that since I did a clone, all the old branches are just references to the old eclipse repo, as shown below. I would really like this to be a "standslone" repository, with all the old branches, commits local to it. I also have the problem that I have a local master and a remote master. I would then push that to some remote for backups.

    I imagine this should be fairly easy to do, but I am close to what I want, and I don't really want to break anything.


    Can someone give me some guidance on how to go from where I am (shown below) to a single repo with all the branches local and one master?

    解决方案

    I went back and did this from scratch one last time. I will document what I did, hopefully it will help someone else find a good approach to migrate an eclipse ADT project to Android Studio and maintain all the git history (it was not obvious to me).

    This assumes you have gone through the migration wizard and have an Android Studio version of your app migrated, but you now want to get all the git history moved over as well. If you have not done that yet, it's fairly strait forward, you can start with the instructions on the developers page found here

    Once you have completed the migration, you will have a copy of your source code in Android Studio, but no git history. Here is how I got mine moved over.

    The basic idea is to create a .git directory that has all the existing history, but structure as what android studio uses, then copy that to your project root. It is a fairly easy process, but I wrote down every gory detail here. You could probably skip some of these steps (like making the new branches), but this is what I did.

    1. make sure you have every thing committed and are pointing to master in you eclipse repo

    2. copy (via cp -rp , not git clone) your existing eclipse git repo to a temp area. Note you are copying the entire repo, all files, directories, etc including the .git directory

    3. go to the temp area and use git to confirm that everything is there, ie no changes are pending

    4. create and switch to a branch called delete_things_not_needed_in_A_S

    5. use rm -r to remove anything that will not exist in android studio. For me I was left with src, my manifest, and the .git directory (you could just selectively copy I guess, rather than copy and delete)

    6. use git to commit these changes and merge them into master, then create a new branch called move_directories_to_match_as_structure.

    7. now go into the temp area and create any directories need to match the Android Studio Structure. for example in AS the package root is under app/src/main/java vs in eclipse it is directly in the root of the project directory.

    8. next move , using mv, the directories you are keeping into the locations they would exist in Android studio. What you should end up with is a directory small subset of what you had in your eclipse repo, but the directories matching what AS is expecting.

    9. remove any "left over" directories, such as the original src (you moved the contents of that to another location, but the directory still exists)

    10. Do an final check, at this point you should only have the directories containing the files in which you want to retain the history for and the .git directory, nothing else.

    11. using git, commit those changes, merge them in to master, and create (and switch to) a final new branch called files_added_by_android_studio

    12. use cp -rp to copy (this is important) ONLY the .git directory into you android studio project root. Note the only change you are making to the migrated android studio project is to copy the .git directory in.

    13. create or or update your .gitignore files in the root of your android project directory and in the app subdirectory with what I have shown below.

    14. in the root of you android studio project, use git gui (or git status) to confirm that there are only a hand full of new files

    15. commit and merge them into master

    16. start android studio and enable version control integration (under VCS on the main menubar)

    That should do it. It sounds more complicated than it really is. Basically you are copying your existing .git folder , modifying it so that it expects to see the changes where they will occur in android studio rather than were they did occur in eclipse and then copying that modified .git folder into you android studio project.

    Here are the two .gitignore files I used:

    in the project root.

    .gradle
    /local.properties
    /.idea/workspace.xml
    /.idea/libraries
    .DS_Store
    /build
    

    in the app folder:

    /build
    

    这篇关于我该如何“解耦"?我的旧Eclipse repro是我的新android studio repro?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆