从刚刚克隆的存储库中将Git结帐导入分支会导致该分支发生未分配的更改 [英] Git checkout from freshly cloned repository into a branch leads to unstaged changes in that branch

查看:137
本文介绍了从刚刚克隆的存储库中将Git结帐导入分支会导致该分支发生未分配的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的git问题。
在检出其中一个分支(即远程跟踪的分支)后,我立即在该分支中获得修改和未分类的更改。
我再次克隆了存储库以验证问题是否存在。



我使用Windows和gitblit作为Git服务器。



你有任何想法,为什么会发生这种情况?



git状态的输出如下:

  $ git status 
#在分支上RSD-5393
#没有为commit提交更改:
#(使用git add< ; file> ...来更新将提交的内容)
#(使用git checkout - < file> ...放弃工作目录中的更改)

#modified:apis.releng / cquery / apis.RSD-4780.cquery
#modified:apis.releng / cquery / apis.RSD-4782.cquery
#modified:apis.releng / cquery / apis .RSD-4786.cquery
#modified:apis.releng / cquery / apis.RSD-4799.cquery
#modified:apis.releng / cquery / apis.RSD-4812.cquery
#modified:apis.releng / cquery / apis.RSD-4815.cquery
#modified:apis.releng / cquery / apis.RSD-4821.cquery
#修改:apis.releng / cquery / apis.RSD-4823.cquery
#修改:apis.releng / cquery / apis.RSD-4826.cquery
#修改:apis.releng / cquery / apis。 RSD-4827.cquery
#modified:apis.releng / cquery / apis.RSD-4828.cquery
#modified:apis.releng / cquery / apis.RSD-4829.cquery
#修改:apis.releng / cquery / apis.RSD-4831.cquery
#修改:apis.releng / cquery / apis.RSD-4846.cquery
#修改:apis.releng / cquery / apis。 RSD-4861.cquery
#modified:apis.releng / cquery / apis.RSD-4862.cquery
#modified:apis.releng / cquery / apis.RSD-4863.cquery
#修改:apis.releng / cquery / apis.RSD-4864.cquery
#修改:apis.releng / cquery / apis.RSD-4865.cquery
#修改:apis.releng / cquery / apis。 RSD-4866.cquery
... ....
没有更改添加到提交(使用git add和/或git commit -a)

.gitconfig:

  [co re] 
autocrlf = true

.gitattributes在存储库中:

 #设置默认行为,以防人们没有设置core.autocrlf。 
* text = auto


解决方案

这可能发生的原因。


  1. 您已启用 core.autocrlf 设置
  2. 您有 .gitattributes 文件,其中包含涂抹或文字过滤



一些背景



autocrlf trys来处理跨平台开发的结束困难,但通常会导致比解决问题更多的问题。

它转换Windows样式行结束符( \r\\\
)将样式文件添加到资源库时,可以对样式文件( \\\
)进行unix。在Windows计算机上工作时,它会在检出文件时将其转换回窗口样式行尾。

虽然总体思路并不差,但它可能导致严重的问题,特别是当它在二进制文件上运行时更是如此。所以大多数情况下,自己处理行结束符是一个明智的选择。



你可以看看这个问题了解更多关于 autocrlf 的信息。



使用 .gitattributes 文件时,可能会出现 smudge 过滤器会在结帐时修改你的文件。另外,即使您的 .gitconfig 也可以使用文本属性来启用 autocrlf c $ c>禁用它。






可能的解决方案



你的情况可能的解决方案是全局禁用 autocrlf git config --global core.autocrlf false )并且从 .gitattributes 文件中删除 * text = auto 行。

您应该继续提交 .gitattributes 文件并将其推送到远程。



与所有其他提交一样,您必须确保你自己这些变化可以在你希望他们的所有分支上得到。它们不会在整个存储库中神奇地可用。



之后,克隆应该有希望得到一个干净的工作目录。






结束语

通常git应该忽略 autocrlf ed文件以避免混乱的状态输出,就像你目前正在经历的那样,但这似乎并不总是工作。另一个避免 autocrlf 的原因。


I have a strange git problem. After checking out one of the branches (that is remotely tracked) I instantly get modified and unstaged changes in that branch. I have cloned the repository again to verify the problem still exists.

I am using Windows and gitblit as Git server.

Do you have any ideas why this could happen?

The output of git status is as follows:

$ git status
# On branch RSD-5393
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   apis.releng/cquery/apis.RSD-4780.cquery
#       modified:   apis.releng/cquery/apis.RSD-4782.cquery
#       modified:   apis.releng/cquery/apis.RSD-4786.cquery
#       modified:   apis.releng/cquery/apis.RSD-4799.cquery
#       modified:   apis.releng/cquery/apis.RSD-4812.cquery
#       modified:   apis.releng/cquery/apis.RSD-4815.cquery
#       modified:   apis.releng/cquery/apis.RSD-4821.cquery
#       modified:   apis.releng/cquery/apis.RSD-4823.cquery
#       modified:   apis.releng/cquery/apis.RSD-4826.cquery
#       modified:   apis.releng/cquery/apis.RSD-4827.cquery
#       modified:   apis.releng/cquery/apis.RSD-4828.cquery
#       modified:   apis.releng/cquery/apis.RSD-4829.cquery
#       modified:   apis.releng/cquery/apis.RSD-4831.cquery
#       modified:   apis.releng/cquery/apis.RSD-4846.cquery
#       modified:   apis.releng/cquery/apis.RSD-4861.cquery
#       modified:   apis.releng/cquery/apis.RSD-4862.cquery
#       modified:   apis.releng/cquery/apis.RSD-4863.cquery
#       modified:   apis.releng/cquery/apis.RSD-4864.cquery
#       modified:   apis.releng/cquery/apis.RSD-4865.cquery
#       modified:   apis.releng/cquery/apis.RSD-4866.cquery
#       ....
no changes added to commit (use "git add" and/or "git commit -a")

.gitconfig:

[core]
autocrlf = true

.gitattributes in repository:

# Set the default behaviour, in case people don't have core.autocrlf set.
* text=auto

解决方案

There are multiple reasons this could happen.

  1. You have the core.autocrlf setting enabled
  2. You have a .gitattributes file which has a smudge or text filter

Some background

autocrlf trys to handle the line-ending difficulties of cross-plattform development but often leads to more problems than it solves.
It converts windows style line-endings (\r\n) to unix style ones (\n) when adding files to the repository. While working on a windows machine it converts them back into windows style line-endings when checking files out.

Although the general idea isn't bad, it can lead to serious problems, especially when it runs amok on binary files. So most of the time it's a wise choice to handle line endings yourself.

You can take a look at this question for more information on autocrlf.

When using a .gitattributes file it's possible that a smudge filter will modify your files on checkout. Alternativly the text attribute can be used to enable autocrlf even if your .gitconfig disables it.


Possible solution

A possible solution in your case is to disable autocrlf globally (git config --global core.autocrlf false) and to remove the * text=auto line from your .gitattributes file.
You should proceed with commiting the .gitattributes file and pushing it to the remote.

As with every other commit you have to ensure for yourself that the changes are available on all branches you wish them to. They won't be magically available in the whole repository.

After that a clone should hopefully result in a clean working directory.


Final note

Usually git should ignore autocrlfed files to avoid cluttered status output like you are currently experiencing, but that doesn't seem to work always. Another reason to avoid autocrlf.

这篇关于从刚刚克隆的存储库中将Git结帐导入分支会导致该分支发生未分配的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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