我创建了一个包含大量源文件和文件夹的文件夹。

现在我想将common文件夹移动到include文件夹中,这样它看起来就像include/common

我试过这些:

Git添加包含 Git mv common/ include/ 但是它会因为这个错误而失败 致命:坏源,源=myrepo/common,目的地=myrepo/include 我尝试了git mv common/ include/common,但我得到了相同的错误

你知道怎么做到吗?


当前回答

我通过这样做解决了这个问题:

电源外壳控制台 运行dir Alt-click并拖动文件/文件夹名称列,然后复制 粘贴到notepad++ 执行replace with regex: replace (.*) with git mv "。\ \ \ 1”。\ \ < New_Folder_Here > \” 从notepad++复制所有文本到powershell 回车

其他回答

另一种方法是将目录中的所有文件移动到子目录(保持git历史):

$(ls | grep -v 'subDir');做git mv $file subDir;完成;

使用Git Tortoise非常简单。

右拖动源到目标(选择源,按住鼠标右键,拖动到目标,释放鼠标)。

将显示一个菜单,其中有Git移动版本的项目和Git移动和重命名版本的项目。

当然,git回购应该在本地克隆

我有类似的问题,但在文件夹,我想移动我有文件,我没有跟踪。

假设我有文件

a/file1
a/untracked1
b/file2
b/untracked2

我想只移动跟踪文件到子文件夹subdir,所以目标是:

subdir/a/file1
subdir/a/untracked1
subdir/b/file2
subdir/b/untracked2

我所做的是:

I created new folder and moved all files that I was interested in moving: mkdir tmpdir && mv a b tmpdir checked out old files git checkout a b created new dir and moved clean folders (without untracked files) to new subdir: mkdir subdir && mv a b subdir added all files from subdir (so Git could add only tracked previously files - it was somekind of git add --update with directory change trick): git add subdir (normally this would add even untracked files - this would require creating .gitignore file) git status shows now only moved files moved rest of files from tmpdir to subdir: mv tmpdir/* subdir git status looks like we executed git mv :)

git最好的一点是您不需要显式地跟踪文件重命名。Git将通过比较文件的内容来找出它。

所以,在你的情况下,不要这么努力:参考:Git mv文档

$ mkdir include
$ git mv common include
$ git rm -r common
$ git add include/common

运行git状态应该显示如下内容:

$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   renamed:    common/file.txt -> include/common/file.txt
#

确保在运行之前已将所有更改添加到暂存区域

git mv oldFolderName newFoldername

Git错误失败

fatal: bad source, source=oldFolderName/somepath/somefile.foo, destination=newFolderName/somepath/somefile.foo

是否有任何未添加的文件,所以我才知道。