Let’s say I have a project that I have worked on for a while,
then I would like to start over with a subset of the files and keep the history of those files.
So is there a way that I can manually merge one file onto the new empty branch?
Or do I need to merge over all the files and then remove the ones I don’t want any more?
I was trying this workflow (but it don’t really work)
$> git init
$> vi file1.c
$> git add file1.c
$> git commit -m 'first commit'
$> vi file2.c
$> git add file2.c
$> git commit -m 'added file2'
$> git log
commit 3788d18e62812d43f6b745f66fdab77081d79711
commit 3ab6959385c09fe2e254104a319a553ee58b198a
$> git checkout @{0}
Note: checking out '3ab6959385c09fe2e254104a319a553ee58b198a'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b new_branch_name
HEAD is now at 3ab6959... first commit
$> git branch -a
* (no branch)
master
$> git branch new_branch
$> git branch
* (no branch)
master
new_branch
$> git checkout new_branch
Switched to branch 'new_branch'
$> git mergetool master file1.c
merge tool candidates: opendiff kdiff3 tkdiff xxdiff meld tortoisemerge gvimdiff diffuse ecmerge p4merge araxis emerge vimdiff
master: file not found
Continue merging other unresolved paths (y/n) ? n
Why do I get “master: file not found”?
How should that merge look like?
Or how do I merge a specific file at a specific commit over to the new branch?
There is a way that kind of does this
Then we have only file1 and kept file1:s history.