Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a GIT project from specific commit of another GIT project

Tags:

git

github

My team has created a gradel based spring GIT project with a lot of configuration. I was wondering if I can save my effort in creating new project require same configuration.

So I was planning to checkout some old commit of existing project, suppose C6. And create a new project from here.

A possible to do this may be;

  1. Checkout C6
  2. Create a new GIT repository.
  3. Manually copy all the contents from old repository and paste to new repository
  4. change the remote of new repository
  5. Push the changes of new repository

But I am not sure whether it is a right approach and gonna work

Please suggest me a correct way to achieve it.

like image 644
Amit Kumar Gupta Avatar asked Sep 17 '25 04:09

Amit Kumar Gupta


1 Answers

You can clone the repository and reset master to C6

$ git reset --hard C6

Remove unwanted branches:

$ git branch -D branch_name

There will be a lot of dangling commits. Check them with:

$ git fsck --no-reflogs

and run these commands to remove dangling commits:

$ git reflog expire --expire=now --all
$ git gc --prune=now

And remember to delete remote origin, or you will be able to push/pull to/from the other repository (considering the code base will not receive the same updates):

$ git remote remove origin
like image 129
Jean Waghetti Avatar answered Sep 18 '25 17:09

Jean Waghetti