我已经看过所有类似的问题但是我已经仔细检查了一些奇怪的东西肯定会发生.
在一台服务器(Solaris with git 1.8.1)上,我克隆了git存储库,然后将.git文件夹复制到现有的实时文件中.这很完美,我可以跑
git status
Run Code Online (Sandbox Code Playgroud)
然后
git diff [filename]
Run Code Online (Sandbox Code Playgroud)
检查任何不同的文件.
在另一台服务器(Solaris with git 1.7.6)上,我做的完全一样
git diff [filename]
Run Code Online (Sandbox Code Playgroud)
即使文件的内容肯定不同,也不显示任何内容.我还测试了添加一个新文件,然后进行编辑.同样的问题,git status将文件显示为已更改但未git diff显示任何内容.如果我下载更改的文件并在本地运行diff,那么我得到diff输出.
Adr*_*ann 71
我将文件添加到索引中:
git add file_name
Run Code Online (Sandbox Code Playgroud)
然后跑:
git diff --cached file_name
Run Code Online (Sandbox Code Playgroud)
你可以在这里看到git diff的描述.
如果你需要撤消你的git add,那么请看这里:如何在提交之前撤消'git add'?
cmc*_*abe 56
有几个原因git status可能会显示差异,但git diff可能不会.
文件的模式(权限位)已更改 - 例如,从777更改为700.
换行样式从CRLF(DOS)更改为LF(UNIX)
找出所发生情况的最简单方法是运行git format-patch HEAD^并查看生成的补丁所说的内容.
Ale*_*rov 47
对我来说,它与文件权限有关.在我的项目中使用Mac/Linux的人似乎提交了一些具有非默认权限的文件,而我的Windows git客户端无法重现这些权限.我的解决方案是告诉git忽略文件权限:
git config core.fileMode false
Run Code Online (Sandbox Code Playgroud)
Jaa*_*kko 34
我有一个问题,一些程序修改了数百行结束,git diff将所有源文件列为已更改.修复行结尾后,git status仍然将文件列为已修改.
我能够通过将所有文件添加到索引然后重置索引来解决此问题.
git add -A
git reset
Run Code Online (Sandbox Code Playgroud)
core.filemode 设置为false.
Ste*_*o M 27
正如在之前的回答中已经指出的,这种情况可能是由于行尾问题(CR/LF vs. LF)引起的。我用这个命令解决了这个问题(在 Git 版本 2.22.0 下):
git add --renormalize .
Run Code Online (Sandbox Code Playgroud)
根据手册:
--renormalize
Apply the "clean" process freshly to all tracked files to
forcibly add them again to the index. This is useful after
changing core.autocrlf configuration or the text attribute in
order to correct files added with wrong CRLF/LF line endings.
This option implies -u.
Run Code Online (Sandbox Code Playgroud)
use*_*062 17
我怀疑你的git安装或你的存储库有什么问题.
试试跑步:
GIT_TRACE=2 git <command>
Run Code Online (Sandbox Code Playgroud)
看看你是否有任何有用的东西.如果这没有帮助,只需看看出现了什么问题:
strace git <command>
Run Code Online (Sandbox Code Playgroud)
小智 10
我有一个类似的问题:git diff会显示差异,但git diff <filename>不会.原来我设置LESS了一个包含-F(--quit-if-one-screen)的字符串.删除该标志解决了这个问题.
跑步git add有时会有所帮助。
Git 状态显示已更改的文件,而 git diff 什么也没显示...
> git status
On branch master
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: package.json
no changes added to commit (use "git add" and/or "git commit -a")
> git diff
>
Run Code Online (Sandbox Code Playgroud)
...运行 git add 解决了不一致问题。
> git add
> git status
On branch master
nothing to commit, working directory clean
>
Run Code Online (Sandbox Code Playgroud)
Line ending issue:
git config --global core.autocrlf true
Run Code Online (Sandbox Code Playgroud)
unix2dos **
Run Code Online (Sandbox Code Playgroud)
git add .
git status
Run Code Online (Sandbox Code Playgroud)
I occasionally run into this issue that git status shows I have files modified while git diff shows nothing. This is most likely an issue of line endings.
The reason I encounter this issue often is that I work on a Windows machine and interact with Git in WSL. Switching between Linux and Windows setting can easily cause this end-of-line issue. Since the line ending format used in the OS differs:
\r\n\nWhen you install Git on your machine, it will ask you to choose line endings setting. Usually, the common practice is to use (commit) Linux-style line endings on your remote Git repository and check out Windows-style on your Windows machine. If you use default setting, this is what Git do for you.
This means if you have a shell script myScript.sh and Bash script myScript.cmd in your repository, the scripts both exist with Linux-style ending in your remote Git repository, and both exist with Windows-style ending on your Windows machine.
I used to check out shell script file and use dos2unix to change the script line-ending in order to run the shell script in WSL. This is why I encounter the issue. Git keeps telling me my modification of line-ending has been changed and asks whether to commit the changes.
Use the default line ending settings and if you change the line endings of some files (like use the dos2unix or dos2unix), drop the changings.
If line-endings changes already exist and you would like to get rid of it, try git add them and the changes will go.
陷入这个问题.我的案子类似于LESS@rcwxok发布的问题.
在我的例子中,我将PAGER环境var 设置为PAGER='less -RSF'.
然而,与之前的答案不同,我不想删除该-F选项,因为我明确地把它放在那里希望防止显示差异,less如果它比屏幕短.
为了得到理想的结果-F,我没有删除,而是添加-X:PAGER='less -RSFX'.这既解决了git diff问题,又防止了显示短差异less.
希望这有助于某人.
我对您的用例的假设:
您有一个包含文件和目录的现有目录,现在想要将其转换为从其他位置克隆的 Git 存储库,而不更改当前目录中的任何数据。
确实有两种方法。
克隆仓库 - mv .git- git reset --hard
您所做的就是此方法 - 将现有存储库克隆到空目录中,然后将该.git目录移动到目标目录中。为了没有问题地工作,这通常需要您运行
git reset --hard
Run Code Online (Sandbox Code Playgroud)
但是,这会更改当前目录中文件的状态。您可以在目录的完整副本/rsync 上尝试此操作并研究发生了什么变化。至少之后您不应该再看到git log和之间的差异status。
初始化新存储库 - 指向原点
第二个不那么令人不安:cd进入你的目的地,然后启动一个新的存储库
git init
Run Code Online (Sandbox Code Playgroud)
然后你告诉这个新的存储库,它在其他地方有一个祖先:
git remote add origin original_git_repo_path
Run Code Online (Sandbox Code Playgroud)
然后平安无事
git fetch origin master
Run Code Online (Sandbox Code Playgroud)
复制数据而不更改本地文件。现在一切都应该好了。
我总是推荐第二种方法,因为这样不容易出错。
| 归档时间: |
|
| 查看次数: |
76035 次 |
| 最近记录: |