How to remove all files in a Git repository that are not in the working directory?

前端 未结 3 1700
半阙折子戏
半阙折子戏 2021-02-07 17:53

I\'m in the process of splitting up an old suite of applications which originally resided in a single Subversion repository.

I\'ve converted it over to a Git repository

3条回答
  •  温柔的废话
    2021-02-07 18:09

    I did this a couple of times - extract commits for a single file and create new repository from them. It goes somewhat like this:

    $ c=10; for commit in $(git log --format=%h -- path/to/file|tac); do
          c=$((c+1))
          git format-patch -1 --stdout $commit > $c.patch
      done
    

    This creates the patch files 11.patch, 12.patch and so on. I then edit these patches (using vim or perl whichever seems best for the job), removing entire hunks for files that I'm not interested in, and maybe fix the names as well in case of renames in the diff hunk header.

    The I'd use git am on the patches on a new git repository. If something doesn't come up right then I nuke the new git repository and edit the patches again and repeat the git am.

    The reason I start counting from 10 is because I'm lazy to prepend a leading 0 to the patch sequence and for commits more than 99 I just start at 99.

提交回复
热议问题