简体   繁体   English

禁用将Visual Studio 2013中的已更改文件自动提交到git

[英]Disable automatic commit of changed files in Visual Studio 2013 to git

Problem: 问题:

When I add a new file into a web project in VS 2013, it is immediately "checked in" to git; 当我在VS 2013中将新文件添加到Web项目时,它会立即“签入”到git; the file is immediately saved and then the "check in" icon appears to the left of the file. 该文件将立即保存,然后在文件的左侧出现“签入”图标。 If I make a change to an existing file, the moment I save the file it "checks in". 如果我对现有文件进行更改,则在保存文件的那一刻“签入”。 Please note that the source git repository is not modified, but I think my local repository is being checked into. 请注意,源git存储库未修改,但我认为我的本地存储库已签入。

Expected behavior: 预期行为:

Add a new file or change an existing one, save, file stays "checked out" and must be manually checked in when ready. 添加新文件或更改现有文件,保存,文件保持“签出”状态,准备就绪后必须手动签入。 This is the desired behavior and was how this project behaved until it started behaving as described on a coworker's system and subsequently appeared on two of my systems. 这是期望的行为,也是这个项目的行为方式,直到它开始表现出来,就像在同事系统上描述的那样,随后出现在我的两个系统上。

Background: 背景:

My coworker managed to return the source control process back to what it was originally by trying a couple dozen different techniques - deletes, resets, etc., but doesn't know what she did to specifically fix it. 我的同事通过尝试数十种不同的技术(删除,重置等)设法使源代码控制过程恢复到最初的状态,但是她不知道自己做了什么来专门修复它。 I did the same on one computer and haven't been able to resolve it, but on my other system I also swung wildly in my approaches and managed to get it working. 我在一台计算机上做了同样的事情,但无法解决它,但是在另一台系统上,我也疯狂地摇摆着,设法使其正常运行。

If I go to the git command line from VS 2013 and enter "git status", I see a list of changed files, but no files that were added. 如果我从VS 2013转到git命令行并输入“ git status”,则会看到已更改文件的列表,但未添加任何文件。 Just above this list of files is the text: 该文件列表的正上方是文本:

On branch master
Your branch is up-to-date with 'origin/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)

I am very familiar with TFS and SourceSafe, but this is the first time I've worked with git. 我对TFS和SourceSafe非常熟悉,但这是我第一次使用git。 I know that they are very different beasts in their approach to source control and also realize that my terminology (ie check in, check out) is more TFS/SS-oriented, so please forgive the error in wording. 我知道它们在源代码控制方法上是非常不同的野兽,并且也意识到我的术语(即检入,检出)更多地面向TFS / SS,因此请原谅措辞上的错误。

Project Info: 项目信息:

This is a VS web project using Angular and Breeze as well as Bower to manage packages. 这是一个使用Angular和Breeze以及Bower来管理软件包的VS Web项目。 The projects that are working "correctly" do not use Angular, Breeze, or Bower. “正确”工作的项目不使用Angular,Breeze或Bower。

Conclusion: 结论:

Can anyone either tell me what is going on here or if there is some way to get my project back to the initial behavior it exhibited? 谁能告诉我这是怎么回事,或者是否有办法使我的项目恢复到最初的状态? Thank you in advance. 先感谢您。

Git does not behave the way other version control systems behave. Git的行为不像其他版本控制系统那样。 The terms "check-in" and "checkout" don't mean the same thing in Git as they do in TFVC or SourceSafe, which could be where your confusion lies. 术语“签入”和“签出”在Git中的含义与在TFVC或SourceSafe中的含义不同,这可能是您感到困惑的地方。

With SourceSafe, when you "checkout" a file, you're telling the version control system that you intend to edit a file, and this blocks other users from editing it in the meantime. 使用SourceSafe,当您“签出”文件时,就是在告诉版本控制系统您打算编辑文件,这会阻止其他用户同时编辑它。 This stems from the fact that tools like SourceSafe and TFVC are centralized, as opposed to Git, which is decentralized. 这源于这样一个事实,即SourceSafe和TFVC之类的工具是集中式的,而Git是分散式的。 With centralized version control systems, everyone is editing the same copy of a file, which is why it becomes necessary to lock and unlock specific files for editing. 使用集中式版本控制系统,每个人都在编辑文件的同一副本,这就是为什么必须锁定和解锁特定文件才能进行编辑的原因。

With Git, you can edit any file at any time, because you're making those edits against your own local copy of the repository. 使用Git,您可以随时编辑任何文件,因为您是根据自己的本地存储库副本进行这些编辑的。 Once you're satisfied with the changes, you push them up to a remote repository, which in your case is probably the repository hosted on your TFS server and associated with your Team Project. 对更改感到满意后,将其推送到远程存储库,在您的情况下,该存储库可能是托管在TFS服务器上并与Team Project相关联的存储库。 There's no gatekeeping behavior to prevent you from making edits, because it isn't necessary. 由于没有必要,没有关守行为可以阻止您进行编辑。 So with Git, a "checkout" is simply a fetch - you tell Git what branch and/or commit you want to load up. 因此,使用Git,“检出”只是一个访存-您告诉Git您要加载的分支和/或提交。

With SourceSafe, you perform a "check-in" to finalize your changes and push them to the central repository. 使用SourceSafe,您可以执行“签入”以完成更改并将其推送到中央存储库。 This frees up the file for editing by other users. 这将释放文件以供其他用户编辑。

With Git, things are a bit different. 使用Git,情况有所不同。 You "commit" changes to your local repository, and then periodically "push" those changes to the remote (shared) repository that your team uses to synchronize changes. 您将更改“提交”到本地存储库,然后定期将这些更改“推送”到团队用来同步更改的远程(共享)存储库。 Since other users are making edits against their own clones of the repository, there's no need for unlocking files by checking them in. 由于其他用户正在对自己的存储库克隆进行编辑,因此无需通过检入来解锁文件。

Another thing that's different about Git is that you can stage or un-stage pending changes. 与Git不同的另一件事是,您可以暂存或取消暂存更改。 Only changes that have been staged by an "add" will be pulled into a commit. 只有通过“添加”进行的更改才会被提交。 Visual Studio basically takes care of this for you with "Included Changes" vs "Excluded Changes". Visual Studio基本上通过“包含的更改”与“排除的更改”为您解决了这一问题。 Essentially, if VS shows a given change as included, then it has been (or will be) staged in Git and will eventually be committed when you hit "Commit". 本质上,如果VS显示已包含给定的更改,则它已经(或将要)在Git中上演,并且在您单击“提交”时最终将被提交。

Regarding the visual cues you're seeing: I believe what you're seeing is Visual Studio telling you that a file has been modified, not that it has been checked-in. 关于您看到的视觉提示:我相信您看到的是Visual Studio告诉您文件已被修改,而不是已签入。 When you make edits in a solution associated with a Git repository, VS will show a red check mark to the left of each modified file in the Solution Explorer window to indicate that it has been edited and has changes pending. 当您在与Git存储库关联的解决方案中进行编辑时,VS将在“解决方案资源管理器”窗口中每个已修改文件的左侧显示一个红色的复选标记,以表明该文件已被编辑并且有待更改。 (New files that have been added will show a green plus-sign next to them.) All this means is that the file has been changed - it is still up to you, the user, to commit or abandon the changes. (已添加的新文件将在它们旁边显示一个绿色加号。)这意味着该文件已被更改-用户(用户)还是要提交或放弃更改。 Once you've committed your changes, you can Sync with the remote repository to publish your changes to the rest of the team. 提交更改后,可以与远程存储库同步,以将更改发布到团队的其他成员。 At this point, if there are any conflicts between other team members' changes and yours, and they're not easily merged, Git/VS will stop and ask you to manually reconcile the conflicts. 此时,如果其他团队成员的更改与您的更改之间存在冲突,并且不容易合并,Git / VS将停止并要求您手动解决冲突。

In your case, Git/VS isn't doing any automatic check-in. 就您而言,Git / VS没有执行任何自动签入。 It's simply indicating that certain files have pending changes. 这只是表明某些文件有待更改。

A full Git tutorial would be beyond the scope of this answer, so I would recommend doing some reading on your own to get a better understanding of how Git works under the hood and how Visual Studio is interacting with it. 完整的Git教程将超出此答案的范围,因此,我建议您自己阅读一些内容,以更好地了解Git的工作原理以及Visual Studio与之交互的方式。

The problem I was having with my project was that my .gitignore file was empty. 我的项目遇到的问题是我的.gitignore文件为空。 Upon copying in the contents of a .gitignore file from a project that was working properly, Visual Studio returned back to showing me my changed items, icons beside the files in the Solution Explorer represented the proper state of a file (ie changed, added, etc.). 从正常运行的项目中复制.gitignore文件的内容后,Visual Studio返回以向我显示更改的项目,解决方案资源管理器中文件旁边的图标表示文件的正确状态(即更改,添加,等等。)。 I don't understand git enough to know why this fixes the problem, but I wanted to post this out here in case anyone else ran across this. 我对git的理解还不够,不知道为什么可以解决此问题,但是我想将其发布在这里,以防其他人遇到该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM