将文件以及git中的历史记录移动到其他文件夹 [英] Moving a file to different folder along with history in git
问题描述
首先,我看了这个问题,它与我在此处要解决的问题完全相同.但是问题是问题中给出的解决方案对我不起作用.
First of all, I had a look at this question which is exactly the same what I am addressing here. But the problem is the solution given in the question, does not work for me.
给出的解决方案是这样的:
The solution given is this:
git filter-branch --tree-filter" cd x;mkdir -p p/q;mv [文件和子目录] p/q";头
移动文件& x
下的子目录到 x/p/q
.
to move files & subdirs under x
to x/p/q
.
这正是我想要的.但这在我尝试时不起作用.
This is exactly what I want. But this does not work when I tried.
我的目录结构是:
mdwtest
|-src
| |-main
| | |-java
| | | |-a.txt
| |-test
| | |-java
我从git本地存储库 mdwtest
目录中的 cmd.exe
中尝试了此命令.我以管理员身份运行 cmd.exe
.
I tried this command from cmd.exe
in mdwtest
directory which is my git local repository. I ran cmd.exe
as administrator.
git filter-branch --tree-filter "cd D:/gittraining/mdwtest/src; mv main/java/ /test/java/" HEAD
但是它在 cmd.exe
控制台中提供了以下输出:
But it gave the below output in cmd.exe
console:
D:\gittraining\mdwtest>git filter-branch --tree-filter "cd
D:/gittraining/mdwtest/src; mv main/java/ /test/java/" HEAD Rewrite
09a1198eeb1bf26a1245ea00cae38f22e91fd708 (1/15)mv: cannot move
`main/java/' to `/test/java' tree filter failed: cd
D:/gittraining/mdwtest/src; mv main/java/ /test/java/ rm: cannot
remove `/d/gittraining/mdwtest/.git-rewrite/revs': Permission denied
rm: cannot remove directory `/d/gittraining/mdwtest/.git-rewrite':
Directory not empty
我可以从中得到的是,将 main/java
移至 test/java
时遇到了一些问题,我对可能发生的事情一无所知阻止了它这样做.
What I can get out of this is that it has some problem over moving main/java
to test/java
and I don't have any clue on what could have prevented it from doing so.
实际上,我希望 src/main/java/a.txt
文件与历史记录一起移至 src/test/java
.
Actually I expected src/main/java/a.txt
file to have moved to src/test/java
along with history.
虽然该解决方案似乎已经为许多人所用,但就我而言,似乎出了点问题.
While the solution seems to have worked for many people, looks like something is going wrong in my case.
您能帮我解释一下我在这里想念什么吗?
Could you help explaining me on what am I missing here ?
推荐答案
mv main/java//test/java/
似乎很奇怪.应该是
mv main/java/ test/java/
( test
,而不是/test
)
除此之外,请确保未在某些编辑器或Windows资源管理器中打开 a.txt
.
Other than that, make sure a.txt
is not opened in some editor or Windows Explorer.
这篇关于将文件以及git中的历史记录移动到其他文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!