如何使用(子)目录在Git中重命名? [英] How to work with (sub)directory renames in Git?

查看:109
本文介绍了如何使用(子)目录在Git中重命名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑使用Git来支持本地开发人员VCS(这是针对多学科开发的)。

以前的做法是,每个试用版本都会重命名顶级目录(并保留一个zip副本)。这对于1-2人的球队来说是相当有效的。版本之间使用超越比较。

然而,快速尝试将Git应用于该方法表明,它'认为'文件被删除并创建了新文件,而不是简单地在新路径上。



因此,我们有

  \GIT-Dir 
\.git
\Master-with-updating-version-name1
\ProjectName
\ Source
files.etc

变成
\.git
\Master-with-updating-version-name2
\ProjectName
\源
files.etc
code>

然后

  \\ \\ GIT-Dir 
\.git
\Master-with-updating-version-name3
\ProjectName
\源
files.etc

鉴于我需要在转换过程中保留旧方法,有哪些选项?

a /如何让Git认识到它只是一个路径更新?

b /如何确保较低级别的文件能够正确跟踪和放大diff'ed?



我在Windows上,使用GitGui 0.13和git 1.7.4.msysgit.0,并安装了GitExtensions 2.21

解决方案

Git不追踪重命名,它追溯地确定它们是 log show 命令。您不必使用git命令来明确地重命名/移动文件或目录。



重命名由差异阈值决定,如果有添加和删除文件和内容非常相似,那么git会认为它是一个重命名/移动。



如果你在git之外重命名你的目录,那么做一个 git status ,你会发现它将它们作为删除对象。现在,将它们添加到您的索引( git add -A 将做到这一点),现在您应该看到它将其视为重命名。


I'm looking at using Git for local developer VCS support (this is for multi-diciplinary development).

Previous practice was that the top level directory would be renamed (and a zip copy kept) for each trial version. It was reasonably effective for 1-2 person teams. Beyond Compare was used between versions.

However a quick try applying Git to the method shows that it 'thinks' that files are deleted and new one created, rather than simply being on a new path.

Thus we have

\GIT-Dir  
  \.git
  \Master-with-updating-version-name1  
    \ProjectName  
      \Source  
        files.etc  

becomes

\GIT-Dir  
  \.git
  \Master-with-updating-version-name2  
    \ProjectName  
      \Source  
        files.etc  

and then

\GIT-Dir  
  \.git
  \Master-with-updating-version-name3  
    \ProjectName  
      \Source  
        files.etc  

Given that I will need to keep alive the old method during the transition, what are the options?
a/ How to get Git to realise that it is simply a path update?
b/ how to make sure that the lower level files become properly tracked & diff'ed?

I'm on Windows, using GitGui 0.13, and git 1.7.4.msysgit.0, and have GitExtensions 2.21 installed

解决方案

Git doesn't track renames, it retrospectively determines them as part of the log and show commands. You don't ever have to explicitly rename/move a file or directory using the git commands.

Renames are determined by a difference threshold, if there's been an addition and a deletion of a file and the content is sufficiently similar, then git will consider it a rename/move.

If you rename your directory outside of git, then do a git status, you'll see it's picked them up as a deletion. Now add them both to your index (git add -A will do it), you should now see it sees them as a rename.

这篇关于如何使用(子)目录在Git中重命名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆