Cloning a Git repo into a new repo - no history commit

So, I'm trying to get around Git and I have a need (why I have such a need, I won’t go into it) to be able to receive files from one repo, via the command line and put them in a completely new repository WITHOUT, taking with me all the previous commit history.

What I'm trying to do at the moment is git init to create a new repository and then grab the files from my existing repo using either a clone or subtree (I don't have my goal completely around this yet so there might be a wrong bark tree), and then add, commit, and then paste them into my new repository.

 git init --- get the files from stock repo --- git add . git commit -m 'Initial commit' git remote add origin <url of my new repo> git push -u origin master 

My repositories are all on Bitbucket, if that matters,

+6
source share
4 answers

You can clone the old repository, for example:

 git clone git@bitbucket.org :username/repository.git 

and then you delete the git directory:

 rm -R .git/ 

Now you create a new repository:

 git init 
+14
source

If you have cloned files from the backup storage, you can do:

 cd yourNewRepo git --work-tree=/path/to/stock/repo add . git commit -m 'Initial commit' 

This means: you consider the files from /path/to/stock/repo as your working tree for your new repo (only for the git add step)

Once the index of your new repo has written these files, you can forget about the reserve fund and transfer these new files (without any previous history) to the new repo.

+1
source

If you have already cloned the TMI repository, you can reset your clone wizard to have only one tip for the story with

 git branch -f master `git commit-tree -m "My new initial commit" origin/master^{tree}` 

and then do as usual, fix the remotes and push the stories around the way you like.

( edit ): if you have a git branch master certificate, it won’t want to rewrite the ref link, but you don’t touch the contents at all, so you can bypass all china manual control and just do it

 git update-ref -m "Truncating history" refs/heads/master \ `git commit-tree -m "My new initial commit" origin/master^{tree}` 

)

+1
source
  • You clone the old repository as follows:

    git clone git@bitbucket.org :username/repository.git

  • Then you delete the git directory:

    rm -rf .git

  • Create a new repository:

    git init

  • Commit the new repository and click on its original beginning

    git push -u origin master

If possible, check the state of the git log to make sure that you have logged the information correctly.

0
source

Source: https://habr.com/ru/post/978207/


All Articles