Move all my commits from one repo to another

I committed several times to the shared repository along with several other authors. Now I want to create my own repository, only my own is committed from . I'm not quite sure how to get started, as I need to keep the original story intact.

+4
source share
3 answers

This is a rather unorthodox problem.

Is this shared repository some kind of project or a free set of unrelated files?

( , - /), , git filter-branch git cherry-pick, git format-patch, .

:

  • , , git log. , SHA, b33787c
  • Cherry pick git cherry-pick b33787c
  • : git format-patch -1 b33787c. 0001-COMMIT-NAME.patch, .

, , , , , , , useful/functional .

+1

, , git filter-branch

- :

git filter-branch --commit-filter '
    if [ "$GIT_COMMITTER_NAME" = "<Your name>" ];
    then
        # use this commit 
    fi' HEAD `
0

:

A, , . , ( 3). 4 . , , 1. 1 A. , B , ( 5/6). .

 1. git clone <git repository A url>
 2. cd <git repository A directory>
 3. git remote rm origin
 4. git filter-branch --subdirectory-filter <directory 1> -- --all
 5. mkdir <directory 1>
 6. mv * <directory 1>
 7. git add .
 8. git commit

:

B, . 3 A B. ( , ) B. . . , . , , , , A. Commit .

 1. git clone <git repository B url>
 2. cd <git repository B directory>
 3. git remote add repo-A-branch <git repository A directory>
 4. git pull repo-A-branch master
 5. git remote rm repo-A-branch

A B

  • .

    git log --all --oneline --graph --decorate --abbrev-commit

  • copy (cherry-pick) A repo B repo.

    git cherry-pick sha-of-commit-one git cherry-pick sha-of-commit-two git cherry-pick sha-of-commit-three

  • .

    git log

  • ( ) .

    git push origin master

  • oldrepo A.

    git remote remove oldrepo A

, A B Repo

  • Find all the commits by author and save their hash in a file:

    git log --author=<author> --format=%H > /tmp/commit-by-author

  • Create a new branch that does not contain this particular author commit. To do this, you can create a new empty branch:

    git checkout --orphan commits-by-author

  • Cherry - select all commits of this author (from A to B Repo):

    tac /tmp/commit-by-x | while read sha; do git cherry-pick ${sha}; done

0
source

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


All Articles