简体   繁体   English

gitignore 文件已在本地删除

[英]gitignore files have been deleted locally

I'm trying to figure out what the best approach is for my situation.我试图找出最适合我的情况的方法。 I had removed everything from my repository and recommitted in order for my gitignore files to work.我已经从我的存储库中删除了所有内容并重新提交,以便我的 gitignore 文件能够工作。 It did, however, I switched to another branch that is still tracking everything, then checked out the original branch, and now those files are not there.然而,它确实如此,我切换到另一个仍在跟踪所有内容的分支,然后检查原始分支,现在这些文件不在那里。

From what I understand this is the correct git behaviour, but I was wondering how I could stop tracking these core files while keeping them locally in order for my site to function?据我所知,这是正确的 git 行为,但我想知道如何停止跟踪这些核心文件,同时将它们保留在本地以使我的网站正常运行?

Should I merge branch branch A (no core files) with branch B (core files), then clear the repository and recommit?我是否应该将分支分支 A(无核心文件)与分支 B(核心文件)合并,然后清除存储库并重新提交?

Actually your question is many fold.其实你的问题是多方面的。 First, when you want to drop files to be tracked further on a branch, but keep the files themselves you will use首先,当您想删除要在分支上进一步跟踪的文件,但保留文件本身时,您将使用

git rm --cached FILE
// possibly edit .gitignore here and `git add .gitignore`
git commit -m "removed the file FILE"

On the other hand, it seems that you want this for a checkout procedure for the contents of web site or something similar.另一方面,您似乎希望将其用于网站内容或类似内容的结帐程序。

As you want to merge A and B ,it seems you want this rule (removing FILE from the index) for all branches.由于您想合并AB ,似乎您希望所有分支都使用此规则(从索引中删除 FILE )。 This can be done with这可以用

git filter-branch -f --index-filter 'git rm --cached --ignore-unmatched HEAD -- FILE'

. . Be careful to have the FILE s in your work tree or have a backup outside of your repository, as the HEAD you fire this command on, will loose all ideas of what these files ever had been, so you cannot check them out again from the history!小心将FILE放在你的工作树中或者在你的存储库之外有一个备份,因为你触发这个命令的 HEAD 将失去这些文件曾经是什么的所有想法,所以你不能从历史! You will either need them in your work tree or have a backup before you filter your history.过滤历史记录之前,您将需要在工作树中使用它们或进行备份。

I dislike the idea, for some reasons, to have the repository that near to a working directory that might contain a mix of tracked files, additional files or even files from other repositories, that track a distinct set of files.由于某些原因,我不喜欢让存储库靠近工作目录的想法,该目录可能包含混合的跟踪文件、附加文件甚至来自其他存储库的文件,这些文件跟踪一组不同的文件。

For such a use case it is often useful to use a second --work-tree for your repository对于这样的用例,为您的存储库使用第二个 --work-tree 通常很有用

git --work-tree=WHERE_YOU_PUBLISH_YOUR_FILES checkout HEAD -- .

to checkout the tracked files from HEAD to your htdocs or whatever.将跟踪的文件从 HEAD 签出到您的htdocs或其他任何内容。 Inside of WHERE_YOU_PUBLISH_YOUR_FILES you can put any other files, without touching the repository.WHERE_YOU_PUBLISH_YOUR_FILES您可以放置​​任何其他文件,而无需触及存储库。

You can check differences of the tracked files, of a repository, against the work tree with您可以根据工作树检查跟踪文件、存储库的差异

git --work-tree=WHERE_YOU_PUBLISH_YOUR_FILES diff

. . You can even check in the files from WHERE_YOU_PUBLISH_YOUR_FILES into the repository您甚至可以将WHERE_YOU_PUBLISH_YOUR_FILES中的文件WHERE_YOU_PUBLISH_YOUR_FILES入存储库

git --work-tree=WHERE_YOU_PUBLISH_YOUR_FILES add -u

To simplify this operation I often use global aliases.为了简化这个操作,我经常使用全局别名。

git config --global alias.public '!git --work-tree $(git config --get public.path)'
git config public.path /var/www/localhost/htdocs

Now you can use现在你可以使用

git public status -s -uno

or similar commands.或类似的命令。

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

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