被忽略的文件仍然显示为已更改,当从索引中删除时,它们会在其他机器上被删除
ignored files still appears as changed, when removing from index, they are removed at other machines
所以这种情况现在发生了很多次,想摆脱它。
当我的框架在我的系统上创建新文件时,我会显示 git 状态,然后看到显示为 "modified",但我不希望将它们添加/更改为 git,我必须将它们添加到 gitignore 文件中,对吗?
但是当我这样做时,它们仍然出现在我的 git 状态中:S
所以我搜索了这个问题,遇到了:
所以我试过了:
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 中的所有文件,而不触及任何机器上的文件系统?
其实我只需要一个"Hey git, go fix your shit and please look at the ignore file before you tell me that things are changed"命令;P
巴特
抱歉这么说,但可以肯定这会按预期工作。
当您执行 git rm --cached
时,您是在告诉 git 从 git 索引中删除文件,从而从存储库中删除文件,但保留它们的本地版本(即本地文件系统上的文件)就位。因此,它们仍将存在于您的计算机上,但是,在其他人的计算机上,它们将作为 git pull/rebase
.
的一部分被删除
这里还有一个更大的问题,即文件 需要 存在于源代码管理中,以及更改 是否应该 确实由忽略。这个问题真的只能由您和您的团队来回答。
如果文件需要存在于源代码管理中,但对它所做的任何更改都应该忽略,那么一种技术我过去使用的是对这些文件执行 git revert
作为我正在使用的构建过程的一部分。例如,在 psake、gulp 或 Cake 脚本中,执行 git revert
作为流程的最后一步。
当我需要 AssemblyInfo.cs
文件存在于源代码管理中时,我使用了此技术,但是,作为构建过程的一部分,此文件已使用当前版本号更新。当 运行 在开发人员机器上进行本地构建时,我不希望将这些更改包含在变更集中,因此我在构建过程中使用了一个额外的步骤来 git revert
对此文件进行更改。
所以这种情况现在发生了很多次,想摆脱它。 当我的框架在我的系统上创建新文件时,我会显示 git 状态,然后看到显示为 "modified",但我不希望将它们添加/更改为 git,我必须将它们添加到 gitignore 文件中,对吗? 但是当我这样做时,它们仍然出现在我的 git 状态中:S 所以我搜索了这个问题,遇到了:
所以我试过了:
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 中的所有文件,而不触及任何机器上的文件系统?
其实我只需要一个"Hey git, go fix your shit and please look at the ignore file before you tell me that things are changed"命令;P
巴特
抱歉这么说,但可以肯定这会按预期工作。
当您执行 git rm --cached
时,您是在告诉 git 从 git 索引中删除文件,从而从存储库中删除文件,但保留它们的本地版本(即本地文件系统上的文件)就位。因此,它们仍将存在于您的计算机上,但是,在其他人的计算机上,它们将作为 git pull/rebase
.
这里还有一个更大的问题,即文件 需要 存在于源代码管理中,以及更改 是否应该 确实由忽略。这个问题真的只能由您和您的团队来回答。
如果文件需要存在于源代码管理中,但对它所做的任何更改都应该忽略,那么一种技术我过去使用的是对这些文件执行 git revert
作为我正在使用的构建过程的一部分。例如,在 psake、gulp 或 Cake 脚本中,执行 git revert
作为流程的最后一步。
当我需要 AssemblyInfo.cs
文件存在于源代码管理中时,我使用了此技术,但是,作为构建过程的一部分,此文件已使用当前版本号更新。当 运行 在开发人员机器上进行本地构建时,我不希望将这些更改包含在变更集中,因此我在构建过程中使用了一个额外的步骤来 git revert
对此文件进行更改。