gitgit-commitgit-history-graph

How to rewrite the master branch history to other Repository master branch


Is there any way or any tool or commands to re write the history of master or some A branch from some commit number to newly created master branch of NEW REPOSITORY with master branch with 0 commits or no history.

In such a way that :

  1. All the previous commits before commit number "45678" should be re written as single commit in the new repository master branch
  2. Rewriting the history should begin from commit "45678"

Thanks


Solution

  • (I don't have a suitable sacrificial repository to test this: you've been warned).

    I would think merge --squash could do this.

    (See this answer as well.)

    Old Content (before question edit)

    Just create the new repository as a new remote on your clone of the original repository; and then push to the new repository.

    git remote add newrep url-to-new-repository
    git push -u newrep master
    

    Repeat the last command for each branch you want to push.