Issue
I have developed two versions of a java lib in Intellij using Ant as the build tool. I am using git for VCS. Its got all the gory update logs, version tags, checkpoints etc.
I recently decided to switch to Gradle based building for future work. My IDE stays the same - Intellij. Though I have been successfully able to configure my build.gradle
file (of the new project) up to a stage where my old sources are now publishable as a Maven dependency
- I am doumbfounded as to how should I migrate the git info. How to achieve this?
Of the top of my head, I could think of a few ways to do this, though I am disastrously unsure. Do shoot them down/affirm them if they are bad/good.
- just copy .git into my new (gradle) project's root and leave Ant specific/related files in the repo.
- before transfering sources to the gradle project, remove tracking of everything but the sources, commit, then transfer the sources and .git.
Env:
IDE: Intellij 2020.3
Gradle: 7.2
OS: Windows 20H2
git: 2.33.0.windows.1 (assume all repos to be local)
Ant: couldn't find ver
FAQs
What have you done so far?
I made a new Gradle based project in Intellij. Then I copied my source files into the new project's sources manually. I then modified the build.gradle
file of this project so everything works in this new avatar.
So what's your problem?
My old Ant based projected had .git in its root folder. My new Gradle based project doesn't have one, for now. If I git init
in the new project's root, the earlier VCS info of the essentially same source code is lost. On the other hand, if I blindly transfer the .git to the new folder, won't git be surprised when it wakes up in a foreign directory? What should I do?
Why did you not just clone the repo and modified it till it became a Gradle project, then opened that in Intellij?
Doing so is cumbersome, fraught with config issues and doesn't leverage tooling. When a new Gradle project is made in Intellij, it automatically creates a lot of stuff - Intellij specific config, Gradle specific config, some other under the hood stuff etc. To transform a non-Gradle dir to the extent that it resembles a Intellij Gradle project seems non-trivial to me, not to mention it may be broken in a dormant way. On the other hand, transfering just the sources is much easier. How to not loose the old .git then is the question.
Solution
The best course of action is to move the .git
folder from the old project folder to the new one along with any source/test files/resources.
In a world where it was possible to pull directly from an Ant project into a Gradle project, a repo. clone would have sufficed, as suggested by @BoristheSpider. However, as also suggested in the comments (by me), cloning and then modding an Ant project till it becomes a Gradle one, isn't easy nor practical, especially when an IDE will create a fresh Gradle project for you or when one is planning to use an IDE anyways.
In such a case, moving .git
(and related sources) is exactly the same as cloning the Ant repo. Only this time, no modding is needed for the IDE does that for you.
... On the other hand, if I blindly transfer the .git to the new folder, won't git be surprised when it wakes up in a foreign directory?
Well, Git can handle it. Though the typical use of Git revolves around bookkeeping of incremental changes to a project and rarely a scrapping of the entire repo dir, it makes no diff. to Git. Even when the only thing left in a dir is .git
adding more things doesn't break VCS continuity with the old files. Think of it as starting a new book in place of the usual chapter.
Answered By - lineage Answer Checked By - Katrina (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.