如何在JGit中重命名文件 [英] How do I rename a file in JGit
问题描述
如何在JGit中重命名文件.也就是说,给定一个名为file1的工作文件.
How do I rename a file in JGit. That is, given a working file named file1.
命令行为:
git mv file1 file2
推荐答案
在Git中没有直接等效于git mv
的内容. git mv
只是
There is no direct equivalent to git mv
in Git. git mv
is just a short hand for
mv oldname newname
git add newname
git rm oldname
分别使用File.renameTo()
或自Java 7起使用Files.move()
移动文件,然后
Respectively, use File.renameTo()
or, since Java 7, Files.move()
to move the file and then
git.add().addFilepattern( "newname" ).call();
git.rm().addFilepattern( "oldname" ).call();
更新Git索引.
赋予addFilePattern()
的路径必须相对于工作目录,并且路径段必须始终由斜杠(/
)分隔,而与使用的文件系统无关.
The paths given to addFilePattern()
must be relative to the work directory and path segments must always be separated by slashes (/
) independent of the file system in use.
请注意,Git不会跟踪重命名或移动.将--follow
选项与git log
结合使用时,它会使用启发式方法尝试检测重命名或移动的文件(请参阅
Note, that Git does not track renames or moves. When using the --follow
option with git log
, it uses heuristics to try to detect renamed or moved files (see Is it possible to move/rename files in Git and maintain their history?)
这篇关于如何在JGit中重命名文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!