CVS 和 Subversion 可以设置为忽略合并中的空格吗?

发布于 2024-07-08 04:49:18 字数 708 浏览 10 评论 0原文

CVS 和 Subversion 都有一个方便的合并功能,因此当您更新已修改的源文件时,它会合并其他人对同一文件所做的更改。

但是,如果您的更改与其他更改不兼容(通常如果您都更改了代码的相同部分),则会产生冲突。 这两段源代码都将包含在合并的文件中,您需要手动找出要保留的更改。 到目前为止一切都很好。

我的问题是,我们中的一些人使用不同的开发环境(Netbeans 与 vi,如果您必须知道的话),并且 Netbeans 具有自动缩进功能,可以重新缩进代码。 因此,当我们合并更改时,有时会遇到巨大的冲突,这些冲突大多是由缩进的简单更改引起的,而不是对代码的真正更改。 通常,这些会产生数百行明显的冲突,必须手动解决,但通常它们会归结为只有几行实际更改。 当某人的编辑器将 UNIX 更改为 Windows 换行符或反之亦然时,会发生类似的情况。

那么 - 在比较两个版本时我可以设置合并来忽略这些“冲突”吗? Diff 有 --ignore-space-change 或 -b 选项,我希望在 cvs 或 svn 中具有基本相同的功能。 我们在不同的项目中使用每种工具,因此我很乐意获得其中一个或两者的答案。

最后两个注意事项:

  • 显然,合并过程必须任意选择在合并文件中使用哪个版本的空白。 我对此很满意 - 我们以后可以随时重新格式化它。
  • 我可以通过更加自律和更频繁地检查——承认和理解来避免这种情况。 但我并不完美。

CVS and Subversion both have a handy merge feature so that when you update a source file that you have modified, it merges in changes that others have made on the same file.

However, if your changes and the other ones are incompatible - generally if you have both changed the same parts of the code - it will create a conflict. Both stretches of source code will be included into the merged file and you need to manually sort out which changes to keep. All fine so far.

My problem is that some of us use different development environments (Netbeans versus vi if you must know) and Netbeans has an auto-indenting feature which re-indents the code. Therefore, when we merge changes, we sometimes get huge conflicts which are mostly caused by simple changes in indentation and are not genuine changes to code. Often these create hundreds of lines of apparent conflicts which have to be manually resolved, but usually they come down to just a few lines of real changes. A similar situation occurs when someone's editor changes unix to Windows newlines or vice versa.

So - can I set merge to ignore these "conflicts" when comparing the two versions? Diff has the --ignore-space-change or -b option and I would like to have essentially the same feature available in cvs or svn. We use each tool on different projects so I would be happy to have the answer for either or both.

Two final notes:

  • clearly the merge process would have to make an arbitrary choice as to which version of the whitespace to use in the merged file. I'm fine with that - we can always reformat it again later.
  • I could avoid some of this by being more disciplined and checking in more often - acknowledged and understood. But I am not perfect.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

幸福%小乖 2024-07-15 04:49:18

对于 SVN:在命令行工具中,有一个选项 -x,您可以将其设置为“b”或“w”以忽略空间更改分别。 所有空格。
您还可以提供第三方工具来进行合并。 因此,如果您有一个忽略空格的合并,则可以使用这个。
TortoiseSVN 一如既往,是所有参数的前端,因此它也支持忽略空格。

svn merge 命令描述 在这里。 您需要的选项是--diff3-cmd

For SVN: In commandline tool, there is the option -x which you can set to "b" or "w" to ignore space changes resp. all spaces.
You can also supply a third party tool for doing the merges. So if you have a merger which ignores whitespaces, you can use this one.
TortoiseSVN, as always, is a frontend to all parameters, so it will support for ignoring whitespaces as well.

The svn merge command is described here. The option you need is --diff3-cmd

月亮是我掰弯的 2024-07-15 04:49:18

对于 Windows 用户,您可以使用 TortoiseSVN(Subversion 的 Windows 资源管理器 shell 扩展),它随 合并支持您所描述内容的功能

忽略行结尾并排除更改
这仅仅是由于差异
行尾样式。

比较空白包括所有
缩进和内联的变化
空白作为添加/删除的行。

忽略空白更改排除
仅由于以下原因而发生的变化
数量或类型的变化
空白,例如 改变
缩进或将制表符更改为
空间。 在有的地方添加空格
以前没有,或者删除
空白仍然完全显示
作为一个改变。

忽略所有空格排除所有
仅空白更改。

For Windows users, you can use TortoiseSVN (a Windows Explorer shell extension for Subversion) which comes with merge features that support what you are describing:

Ignore line endings excludes changes
which are due solely to difference in
line-end style.

Compare whitespaces includes all
changes in indentation and inline
whitespace as added/removed lines.

Ignore whitespace changes excludes
changes which are due solely to a
change in the amount or type of
whitespace, eg. changing the
indentation or changing tabs to
spaces. Adding whitespace where there
was none before, or removing a
whitespace completely is still shown
as a change.

Ignore all whitespaces excludes all
whitespace-only changes.

拍不死你 2024-07-15 04:49:18

TortoiseMerge 没有任何 CLA(命令行参数)来忽略空格并忽略大小写。 经过一番查找,似乎还是可以通过调整注册表值来实现。

/* DisableWhitespaceDifferences and DisableCaseDifferences. 
* The settings for TortoiseMerge is stored in Registry in CurrentUser\Software\TortoiseMerge\
* DWORDS stored the property values.
* 
* IgnoreWS         :   Set to 1 to ignore the whitespace differences. 
*                      Set to 0 to allow the whitespace differences.             
* IgnoreEOL        :   Set to 1 to ignore the End of Line differences. 
*                      Set to 0 to allow the End of Line differences.             
* CaseInsensitive  :   Set to 1 to ignore the Case differences. 
*                      Set to 0 to allow the Case differences.             
*/

// Get the key from the registry
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\TortoiseMerge", true))
{
   if (key != null)
   {
        // Set the IgnoreWS and IgnoreEOL DWORDs based on DisableWhitespaceDifferences is set or not
        key.SetValue("IgnoreWS", DisableWhitespaceDifferences ? 1 : 0, RegistryValueKind.DWord);
        key.SetValue("IgnoreEOL", DisableWhitespaceDifferences ? 1 : 0, RegistryValueKind.DWord);

        // Set the CaseInsensitive DWORD based on DisableCaseDifferences is set or not
        key.SetValue("CaseInsensitive", DisableCaseDifferences ? 1 : 0, RegistryValueKind.DWord);

        // close key
        key.Close();
    }
}

TortoiseMerge doesn't have any CLA (Command Line Arguments) to ignore the whitespace and ignore the case. After searching a lot it seems that it can be achieved still by tweaking the registry values.

/* DisableWhitespaceDifferences and DisableCaseDifferences. 
* The settings for TortoiseMerge is stored in Registry in CurrentUser\Software\TortoiseMerge\
* DWORDS stored the property values.
* 
* IgnoreWS         :   Set to 1 to ignore the whitespace differences. 
*                      Set to 0 to allow the whitespace differences.             
* IgnoreEOL        :   Set to 1 to ignore the End of Line differences. 
*                      Set to 0 to allow the End of Line differences.             
* CaseInsensitive  :   Set to 1 to ignore the Case differences. 
*                      Set to 0 to allow the Case differences.             
*/

// Get the key from the registry
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\TortoiseMerge", true))
{
   if (key != null)
   {
        // Set the IgnoreWS and IgnoreEOL DWORDs based on DisableWhitespaceDifferences is set or not
        key.SetValue("IgnoreWS", DisableWhitespaceDifferences ? 1 : 0, RegistryValueKind.DWord);
        key.SetValue("IgnoreEOL", DisableWhitespaceDifferences ? 1 : 0, RegistryValueKind.DWord);

        // Set the CaseInsensitive DWORD based on DisableCaseDifferences is set or not
        key.SetValue("CaseInsensitive", DisableCaseDifferences ? 1 : 0, RegistryValueKind.DWord);

        // close key
        key.Close();
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文