0

我有一些csv我定期修改的文件,它们实际上并不包含任何敏感信息,它们只是用作程序的导入,我会根据要求对其进行修改。

最近我发现了处理更改的更有效方法,但我在项目外部的临时 git 存储库上对其进行了测试。

由于这很成功,我现在想要对其进行更改git cherry-pick范围,所以首先我将临时 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)

(事后看来,我认为这是一个错误,我应该在现有项目中削减另一个分支,但我离题了)

临时存储库只有一个主分支,并且所有内容都在项目的根目录中完成了一系列提交。

当我cherry-pick对我的项目和本地分支进行更改时,这些csv文件最终都在我的项目的根目录中,但它们属于src/csv我的项目的文件,所以我决定rebase从一开始就进行交互提交的范围(减去 1 次提交)并编辑每个,以便更改显示在我的项目存储库中的src/csv目录而不是根目录中。

但是我的问题是,如果我想这样做,我应该使用git mv移动文件还是仅使用标准 bashmv命令,然后使用 rebase 重新应用每个更改,并将相应的提交消息添加到临时项目中。

到目前为止,我已经尝试git mv -f在第一次提交时移动文件,并且在运行之前提交它们时甚至没有提到更改git rebase --continue

我还应该做些什么来使这个过程更顺利,我假设我应该使用mv而不是git mv -f因为在提交之前更改似乎以这种方式显示。

我还想保留提交消息,而不必从旧仓库的日志中复制它们。

4

1 回答 1

1

git mv没有什么神奇的。Git 不记得重命名,而是从文件的内容中推断出它们。您可以使用git mv或者您可以使用mv然后git add您的更改。

git mv some.csv src/some.csv

相当于

mv some.csv src/some.csv
git add some.csv src/some.csv

“添加”已删除的文件有点奇怪。您正在将更改“添加”到暂存区域,此更改恰好是删除文件。


您所做的更改,将文件移动到子目录,可以使用git filter-branch.

git filter-branch --index-filter 'git mv *.csv src/' <range of changes>
于 2019-10-02T16:23:12.920 回答