I have one folder, let's call it Product1.0
and multiple other folders like Product1.1
, Product1.2
, etc which are modified versions of Product.
I want to put this entire thing in one local git repo, and manage it such that content of Product1.1
will be the next version (commit) of Product1.0
, Product1.2
will be next version of Product 1.1
and so on. And if I want to revert back to any of the other versions, I can just checkout to previous versions.
Suggestions on how to do this?
🤔 I realized AFTER I wrote this long answer that (I think) you don't want to maintain your separate product folders and do want to merge them into a single repo. In that case, most of this answer reflects my misunderstanding and and doesn't apply to you. Let me know in a comment below and I will delete it. 😢
Also, in that case, your question is a duplicate of How do I migrate multiple versions of code into a single Git repo? which I had already linked below. Also let me know if that answers to that question are not good enough for you.
That's not how Git's versioning and branching naturally work. Git does not use separate directories (folders) to manage versions or branches, just as your editor's undo/redo history doesn't use different tabs.
You can ignore Git's model and do what you describe in Git, but it will come with a lot of pain and you will lose much if not most of the benefits of Git, AND you will confuse anyone else who ever works on your code. It is not worth it. But you can get what you want without violating the tenets of the CVS you are using. Here are your options:
If you are adamant about versions stored in your VCS as different directories, you can switch to a different VCS that maps branches to directories. If I remember correctly, i think that's how Perforce works.
Given that you write
And if I want to revert back to any of the other versions, I can just checkout to previous versions.
I'm pretty sure you do not want versions to exist side-by-side in separate directories, since the point of reverting is to swap all the code for one version out for the code of another, i.e. not switch directories. Just like undo/redo swaps out the text in your editor in-situ, rather than switching tabs.
In that case, you should use Git as it was intended, with each branch/version in the same logical directory, but checked out one-at-a-time into a single physical directory, or checkout out many at a time into separate physical directories (see below), as your needs dictate.
The steps for putting your existing versions-in-separate-folders into a single logical git repo folder are not trivial, and must be done carefully and with an understanding of how Git works, so is beyond the scope of this question.
See How do I migrate multiple versions of code into a single Git repo?, but both of the current answers are just outlines of what you'd need to do, and neither creates branches (needed if you want to do work on each version in parallel) or tags (mark versions in the commit history with names, like V1.0.2).
If you have trouble figuring it out, ask a new question here, or make a comment below and I'll see if I can provide a more detailed answer to the How to Migrate question linked above.
Whether you want different versions in different directories because you want to work on them simultaneously or because you need to run/deploy multiple versions simultaneously, you can achieve this with Git. There are a couple of ways to do this:
git worktree
If you are working solo, and your Product repo is local, git worktree
will let you checkout different branches of your repo into separate local directories ("worktrees" in Git parlance). In other words, you can recreate your current directory structure if that's what you need.
If you are working on a team, then you will have a central repo, either on your own server or hosted on a provide such as GitHub, GitLab or Gitea.
In that case, you can clone different branches of the central repo into separate local directories using the standard git clone
command.