问题描述
我很难理解一些git/DCVS概念.这是发生了什么:
I'm having a hard time understanding some git/DCVS concepts. Here's what happened:
- 我创建了一个git项目,并从SVN存储库中导入了它
- 我做了一些承诺
- 我想尝试一些东西,所以我创建了一个名为 constants-update 的分支.
- 我切换到常量更新分支,移动了一些文件,删除了其他文件并添加了更多
- 我致力于这个分支机构
- 现在我正尝试使用
git checkout master
切换到我的master分支 - 我收到此错误:错误:您对'src/groovy/Constants.groovy'进行了本地更改;无法切换分支.
- I created a git project, and imported it from an SVN repo
- I made some commits
- I wanted to experiment something, so I created a branch called constants-update
- I switched to constants-updatebranch, moved some files, deleted others and added many more
- I committed to this branch
- Now I'm trying to switch to my master branch using
git checkout master
- I got this error: error: You have local changes to 'src/groovy/Constants.groovy'; cannot switch branches.
我对DCVS的理解是,即使我提交了文件,即使某个分支具有比其他分支更多或更少的文件,我也可以随意切换分支.我尝试使用 git commit -a
提交并切换到master分支,但是我遇到了同样的错误.
My understanding of DCVS is that I can switch branches at will, even if some branch has more or less files than the others, as long as I commit my files. I've tried committing with git commit -a
and switching to master branch, but I have the same error.
作为旁注,当我提交git时,我警告我LF将被CRLF取代,并警告我一些结尾的空格;我提交后,我会执行 git status
,并且一堆文件始终显示为 #modified ...
.
As a side note, when I commit git warns me that LF will be replaced by CRLF and warns me about some trailing whitespaces also; after I commit I do a git status
and a bunch of files always appear as #modified ...
.
这与git/ windows 有关,还是我不正确理解应该发生什么?我只想切换到我的主分支,而不会丢失其他分支中的更改.
Is this related to git/windows, or I do not understand correctly what it is supposed to happen? I just want to switch to my master branch without losing my changes in the other branch.
推荐答案
我解决了入侵我的预提交钩子(在 .git/hooks/pre-commit中注释这些行代码>和
#
):
I solved the problem hacking my pre-commit hook (commenting these lines in .git/hooks/pre-commit
with a #
):
# if (/\s$/) {
# bad_line("trailing whitespace", $_);
# }
这篇关于Git-切换分支机构(Windows)&未提交的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!