【发布时间】:2020-01-31 21:06:07
【问题描述】:
我有一些csv 文件,我会定期修改,它们实际上不包含任何敏感信息,它们只是用作程序的导入,我会根据要求对其进行修改。
最近我发现了处理更改的更有效方法,但我在项目外部的临时 git 存储库上对其进行了测试。
由于这很成功,我现在想将git cherry-pick range of changes 添加到它,所以首先我将临时 git repo 作为远程添加到我的项目中。
# In my project I added a remote of the test repo with
# a copy of the csv's in the HEAD of my main project.
git remote add tempchanges <path-to-test-repo>
# Created a new branch in my project to test this out in.
git checkout -b new/9_30_2019
# Cherry-picked the changes from the remote test repo, but they ended up in the root of the project.
git cherry-pick <start-commit-in-test-repo>..<head-commit-in-test-repo>
# Started a rebase
git rebase -i <start-commit-in-test-repo>~1
# (`edit`ed each commit in the rebase)
(事后看来,我认为这是一个错误,我应该在现有项目中削减另一个分支,但我离题了)
临时存储库只有一个 master 分支,并且所有内容都在项目的根目录中完成了一系列提交。
当我将 cherry-pick 更改到我的项目并进入本地分支时,csv 文件最终都在我的项目的根目录中,但它们属于我的项目的 src/csv 文件,所以我决定从提交范围的开始(减去 1 次提交)开始进行交互式 rebase 并编辑每个,以便更改显示在我的项目存储库中的 src/csv 目录而不是根目录中。
但我的问题是,如果我想这样做,我应该使用 git mv 移动文件还是只使用标准 bash mv 命令,然后使用 rebase 重新应用每个更改并添加相应的提交消息到临时项目。
到目前为止,我已经尝试使用 git mv -f 在第一次提交时移动文件,并且在运行 git rebase --continue 之前提交它们时甚至没有提及更改。
我还应该做些什么来使这个过程更顺利,我假设我应该使用mv 而不是git mv -f,因为在提交之前更改似乎以这种方式显示。
我还想保留提交消息,而不必从旧仓库的日志中复制它们。
【问题讨论】:
标签: git git-rebase git-remote git-cherry-pick git-mv