I've erroneously written changes into a copy of a remote repository that is no longer version controlled by Git. I need to convert this local directory back into a Git repository, compare differences with the remote branch, and then commit only those changes on top as you would normally.
What is the best way of doing this?
The easiest solution I would see is to use git diff
by specified the actual files who changed.
Something along the line of:
git diff non_git_dir/the-files-*.js git-dir/the-files-*.js > patch.diff
If you have both directory on your disk and can relatively easily point the files you know have changed, it would generate a reasonably good diff file.
Then you would just have to apply the diff on you git managed directory:
git apply patch.diff
And from there you can commit or do what you want.
If however the changes are to broad or you can't have the files on your disk for any reason. Maybe you can try to:
git init
git add .
git commit -m"ALL THE THINGS"
git remote add new git@github:newrepo.git
git diff master new/master
Of course there is also the possibility to just copying the files over and check any potential code lost before committing.
But it sounds like cheating
My two cents...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.