Replace GitHub repository with a new Android Studio project while preserving old commits

前端 未结 1 614
不知归路
不知归路 2020-12-05 16:16

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 Andr

相关标签:
1条回答
  • 2020-12-05 17:08
    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 > Project from Version Control > Git. 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

    • Git Basics - Recording Changes to the Repository
    0 讨论(0)
提交回复
热议问题