git 将/mv目录复制到git中的另一个目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6866833/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
copy/mv directory to another directory in git
提问by icn
I have a
我有一个
dir1/ contains a lot files and subdirecties, I want to change the directory name to dir2/ . I tried
dir1/ 包含很多文件和子目录,我想将目录名称更改为 dir2/ 。我试过
git mv dir1/ dir2/
git mv dir1/ dir2/
I got this message:
我收到了这条消息:
fatal: renaming 'dir1' failed: Permission denied
update:
更新:
I ran from git for windows command line http://code.google.com/p/msysgit/
What is the correct command?
我从 git for windows 命令行运行http://code.google.com/p/msysgit/
什么是正确的命令?
采纳答案by Leif Andersen
You can just use standard unix tools, or whatever your OS is. So:
你可以只使用标准的 unix 工具,或者任何你的操作系统。所以:
mv dir1 dir2
should work. Just make sure you add both dir1 and dir2 to the staging area after you've done that, so that you commit the changes.
应该管用。只需确保在完成后将 dir1 和 dir2 添加到暂存区,以便提交更改。
An example of how to commit the change (once done) could be:
如何提交更改(一旦完成)的示例可能是:
git add dir1 dir2 && git commit dir1 dir2
There's probably other ways to do it too.
可能还有其他方法可以做到。
回答by Bram Schoenmakers
It could also be that the directory (or a file within) is being used by another program, which prevents you from doing anything with that folder. Only on Windows, obviously.
也可能是该目录(或其中的文件)正被另一个程序使用,这会阻止您对该文件夹执行任何操作。显然,仅在 Windows 上。
Use the Process Explorerif you're unsure which program has captured that directory/file.
如果您不确定哪个程序捕获了该目录/文件,请使用Process Explorer。
回答by msgrockclimber
Both the source and target directory need to be checked into the git repository. If you are moving dir1 to dir2 and dir2 hasn't been committed yet, you will get this error message.
源目录和目标目录都需要检入 git 存储库。如果您将 dir1 移动到 dir2 并且 dir2 尚未提交,您将收到此错误消息。
回答by Vivian De Smedt
I had the same problem. TGitCache.exe was the process that were preventing the folder to be renamed. Using TaksExplorer I have killed the process and run the command from Git Bash command prompt.
我有同样的问题。TGitCache.exe 是阻止重命名文件夹的进程。使用 TaksExplorer,我终止了进程并从 Git Bash 命令提示符运行命令。
回答by Dave
I'm running git in cygwin. I had the same problem until I removed untracked files from the directory to be renamed. That allowed the git mv
to complete properly.
我在 cygwin 中运行 git。我遇到了同样的问题,直到我从要重命名的目录中删除了未跟踪的文件。这允许git mv
正确完成。
If you see untracked files in your directory to be renamed when you run git status
then you'll have to move those files somewhere else temporarily and bring them back in after the git mv
.
如果您在运行时看到目录中未跟踪的文件要重命名,git status
那么您必须暂时将这些文件移到其他地方,并在git mv
.