本文介绍了Git-切换分支机构(Windows)&未提交的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难理解一些git/DCVS概念.这是发生了什么:

I'm having a hard time understanding some git/DCVS concepts. Here's what happened:

  1. 我创建了一个git项目,并从SVN存储库中导入了它
  2. 我做了一些承诺
  3. 我想尝试一些东西,所以我创建了一个名为 constants-update
  4. 的分支.
  5. 我切换到常量更新分支,移动了一些文件,删除了其他文件并添加了更多
  6. 我致力于这个分支机构
  7. 现在我正尝试使用 git checkout master
  8. 切换到我的master分支
  9. 我收到此错误:错误:您对'src/groovy/Constants.groovy'进行了本地更改;无法切换分支.
  1. I created a git project, and imported it from an SVN repo
  2. I made some commits
  3. I wanted to experiment something, so I created a branch called constants-update
  4. I switched to constants-updatebranch, moved some files, deleted others and added many more
  5. I committed to this branch
  6. Now I'm trying to switch to my master branch using git checkout master
  7. 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)&未提交的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 21:12