用新的Android Studio项目替换GitHub存储库,同时保留旧的提交 [英] Replace GitHub repository with a new Android Studio project while preserving old commits

查看:210
本文介绍了用新的Android Studio项目替换GitHub存储库,同时保留旧的提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个旧的Android项目,我认为我已经开始使用Eclipse或旧版Android Studio。无论如何,项目结构与Android Studio如何使用Gradle组织事物完全不同。而不是试图更新每个文件位置,我刚刚用一个使用相同名称的新项目开始。



现在我想更新我的GitHub存储库,但是我没有想要失去我以前的提交,它会执行像 git push --force origin master 这样的显式操作(参见此处此处)。



这个问题类似于替换GitHub repo,同时保留问题,维基等,但我想知道的Android Studio的具体情况。



我会尝试找出一种方法来根据此处此处。如果我能解决它,我会在下面发表我的答案。 重命名您的当前的项目文件夹(你想放在GitHub上的新文件夹)变成类似于 MyProjectBackup 的东西。在Android Studio中,转至文件>新建>来自版本控制的文件> GitHub 然后使用您的GitHub用户名和密码登录,然后从您的GitHub回购列表中选择旧项目的存储库名称。继续通过导入向导,您应该最终在Android Studio中使用旧项目。 (现在,例如,您的旧项目位于 MyProject 中,并且您的新项目位于 MyProjectBackup 中)。


  • 手动删除除 .git .gitignore (也许是自述文件和许可证)从 MyProject 项目文件夹。 (我试过 git rm -r * 但我是获取错误。)


  • 从命令行中你的 MyProject 文件夹运行

      git add -u 
    git提交-m在添加更新项目之前删除旧文件

    这将更新工作树中的跟踪文件,以查看您刚刚进行的所有手动删除操作。 然后运行

      git add。 
    git commit -m新更新的项目
    git push


  • 现在您的新项目将位于GitHub中,并且旧项目的提交历史记录仍可用。



    有用的阅读




    I had an old Android project that I think I had started in Eclipse or some old version of Android Studio. Anyway the project structure was completely different from how Android Studio organizes things now with Gradle. Rather than try to update every file location I just started over with a new project using the same name.

    Now I would like to update my GitHub repository but I don't want to lose my previous commits, which doing something like git push --force origin master would apparently cause (see here and here).

    This question is similar to Replace GitHub repo while preserving issues, wiki, etc, but I would like to know for the specific case of Android Studio. Also the current answer to that question does not preserve the commit history.

    I am going to try to figure out a way to do this based on hints from here and here. If I can solve it, I will post my answer below.

    解决方案

    1. Rename your current project folder (the new one you want to put on GitHub) to something like MyProjectBackup.

    2. In Android Studio, go to File > New > File from Version Control > GitHub. Then log in with your GitHub username and password and select your old project's repository name from the list of your GitHub repos. Continue through the import wizard and you should end up with your old project in Android Studio. (Now, for example, your old project is in MyProject and your new project is in MyProjectBackup).

    3. Manually delete everything except for .git and .gitignore (and maybe the readme and license) from your MyProject project folder. (I had tried git rm -r * but I was getting errors.)

    4. From the command line in your MyProject folder run

      git add -u
      git commit -m "deleting old files before adding updated project"
      

      This will update the tracked files in the working tree for all the manual deletions you just made.

    5. Copy in all your new files from MyProjectBackup. Then run

      git add .
      git commit -m "new updated project"
      git push
      

    Now your new project will be in GitHub and the old project's commit history will still be available.

    Helpful reading

    这篇关于用新的Android Studio项目替换GitHub存储库,同时保留旧的提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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