E
E
Evgeny Koryakin2021-07-25 03:46:55
git
Evgeny Koryakin, 2021-07-25 03:46:55

How to download version 1 while already having version 2?

Hello!
On GitHub, I immediately uploaded version 2.0, but how do I add version 1.0 as the very first commit?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Kuznetsov, 2021-07-26
@zettend

So, you started the commit chain from the wrong state of the project. The very first commit already contains a lot of files (it was a repository that was initialized in an already quite mature project).
So you will have to start a new root branch that is not a continuation of your existing commit tree. This is such an orphan branch that has no parents.
git switch --discard-changes --orphan v1
And create an empty initial commit, which we will use as a stove from which we dance. Then clean up the working directory of the project, copy the files of the first version there and create a commit with this version. Then all that remains is to switch back to the branch with the second version and transplant it on top of the first version
git commit --allow-empty -m "Initial empty commit"
git switch main
git rebase v1
So we actually recreated the branch, so in order to recreate it on the github too, you have to send it with the force key
git push --force

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question