Git - 切换分支(窗口)&无法改变的变化 [英] Git - Switching branches (windows) & uncommited changes

查看:212
本文介绍了Git - 切换分支(窗口)&无法改变的变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难理解一些git / DCVS的概念。以下是发生了什么:


  1. 我创建了一个git项目,并从SVN仓库导入它

  2. 我做了一些提交

  3. 我想试验一些东西,所以我创建了一个名为常量更新的分支。到常量更新分支,移动了一些文件,删除了其他人并添加了更多

  4. 现在我试图使用 git checkout master
  5. 切换到我的主分支
  6. 出现此错误:错误:您对src / groovy / Constants.groovy进行本地更改;无法切换分支。

我对DCVS的理解是,我可以随意切换分支,即使某些分支具有更多或更少的文件比其他人,只要我提交我的文件。我已经尝试使用 git commit -a 提交并切换到主分支,但是我有同样的错误。

请注意,当我提交git时,我会告诉我LF将被CRLF取代,并警告我一些尾随的空格;在我提交之后,我做了一个 git status ,一堆文件总是显示为 #modified ... 。 p>

这是与git / windows 相关的,还是我无法正确理解应该发生的事情?我只想在其他分支中切换到我的主分支而不会丢失我的更改

我解决了这个问题破解我的预先提交钩子(在 .git / hooks / pre-commit 中用>注释这些行) ):

 #if(/ \s $ /){
#bad_line (尾随空白,$ _);
#}


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

  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.

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.

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 ....

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.

解决方案

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 - 切换分支(窗口)&无法改变的变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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