Ionică Bizău
Ionică Bizău

Reputation: 113335

How to create a new git repository with a file that is already in a git repository, keeping the commits

I have a repository foo that contains a file Alice.js.

I want to take that file (that has lots of commits) and create a new repository only with the commits from that file.

How can I do this?


Example:

Initial repository

.
+- Alice.js
+- Bob.png
+- Another.file

do magic

New repository

.
+- Alice.js

The new repository contains only the commits from Alice.js.

Upvotes: 2

Views: 40

Answers (1)

nitishagar
nitishagar

Reputation: 9403

You might want to try sparse checkout. The steps would be:

Create a empty repo with remote, as follows:

git init <repo>
git remote add -f origin <url>

Then, git config core.sparsecheckout true. Add files to checkout to .git/info/sparse-checkout.

And finally you can pull in the changes: git pull origin master.

Upvotes: 1

Related Questions