被忽略的文件仍显示为已更改,从索引中删除时,它们将在其他计算机上删除

时间:2016-08-24 08:19:40

标签: git gitignore

所以现在这种情况发生了多次,并希望摆脱它。 当我的框架在我的系统上创建新文件时,我会执行git状态,然后看到显示为“已修改”,但我不希望将它们添加/更改为git,我将不得不将它们添加到gitignore档案,对吗? 但是,当我这样做时,他们仍然出现在我的git状态:S 所以我搜索了这个问题,并且遇到了:

https://stackoverflow.com/questions/9750606/git-still-shows-files-as-modified-after-adding-to-gitignore#=

所以我试过了:

git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

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:   bootstrap/cache/services.php <<< so these 3 are already in gitignore, but still shows up :S
        modified:   composer.lock <<< so these 3 are already in gitignore, but still shows up :S
        modified:   npm-debug.log <<< so these 3 are already in gitignore, but still shows up :S

no changes added to commit (use "git add" and/or "git commit -a")
folder/projectfolder git rm -r --cached  bootstrap/cache/services.php
rm 'bootstrap/cache/services.php'
folder/projectfolder git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        deleted:    bootstrap/cache/services.php

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:   composer.lock
        modified:   npm-debug.log

folder/projectfolder git rm -r --cached  composer.lock
rm 'composer.lock'
folder/projectfolder git rm -r --cached npm-debug.log
rm 'npm-debug.log'
folder/projectfolder git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        deleted:    bootstrap/cache/services.php
        deleted:    composer.lock
        deleted:    npm-debug.log

folder/projectfolder git commit -m "clean gitindex"
[master 084a4e1] clean gitindex
 Committer: ********

 3 files changed, 13823 deletions(-)
 delete mode 100644 bootstrap/cache/services.php
 delete mode 100644 composer.lock
 delete mode 100644 npm-debug.log
folder/projectfolder git status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
  (use "git push" to publish your local commits)

nothing to commit, working directory clean
folder/projectfolder git push
warning: <<<message and login removed here>>>
Counting objects: 9, done.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (6/6), 582 bytes | 0 bytes/s, done.
Total 6 (delta 4), reused 0 (delta 0)
To https://*****@bitbucket.org/*****/*****.git
   45ty54y4y54y******y4t43at  master -> master

但是在这样做之后,当我的同事从git中取出我的更改时,3个文件实际上已从他的系统中删除,而不仅仅是从git索引中删除。我怎么能让git忽略我在gitignore中的所有文件,而不需要触及任何机器上的文件系统?

其实我只需要一个“嘿git,去修理你的狗屎,请在你告诉我事情发生变化之前先查看忽略文件”命令; P

巴特

1 个答案:

答案 0 :(得分:1)

很抱歉,但相当确定这是按预期工作的。

当你执行git rm --cached时,你告诉git从git索引中删除文件,从而删除存储库,但要保留它们的本地版本(即本地文件系统上的文件)。因此,它们仍将存在于您的计算机上,但是,在其他人的计算机上,它们将作为git pull/rebase的一部分被删除。

关于源控件中是否存在需要文件以及是否确实被忽略,还有一个更大的问题。这个问题实际上只能由你和你的团队来回答。

如果源控件中存在需要文件,但对其执行的任何更改都应忽略,那么我过去使用的一种技术是在我正在使用的构建过程中执行git revert这些文件。例如,在psake,gulp或Cake脚本中,执行git revert作为该过程的最后一步。

当我需要AssemblyInfo.cs文件存在于源代码控制中时,我使用了这种技术,但是,作为构建过程的一部分,此文件将使用当前版本号进行更新。在开发人员计算机上本地运行构建时,我不希望这些更改包含在变更集中,因此我在构建过程中使用了一个额外步骤来git revert对此文件所做的更改。