简体   繁体   English

取消跟踪 git 文件

[英]Untrack git file

Here is the think, I have a database field with some html.这是我的想法,我有一个带有一些 html 的数据库字段。

<span class="orange"><a href="/pdf/MY_PDF.pdf">Title</a></span>

Last day, my boss told me he wanted to change this pdf.前一天,我的老板告诉我他想修改这个 pdf。 So, i thought I just had to put the new file in the folder and change his name inside the database (MY_PDF2.pdf) for example.所以,我想我只需要将新文件放在文件夹中,然后在数据库(MY_PDF2.pdf)中更改他的名字。

But this is tricky because the file is tracked by git... so to see the new pdf I had to commit just this single PDF.但这很棘手,因为该文件是由 git 跟踪的……所以要查看新的 pdf,我只需要提交这个单一的 PDF。 The thing is it's a customer file... so if we have to make some commit each time they want to change... this is crazy.问题是它是一个客户文件......所以如果我们每次他们想要改变时都必须做出一些承诺......这太疯狂了。

So I just want to say to git that the file doesn't need to be tracked.所以我只想对 git 说这个文件不需要被跟踪。

It's under Symfony and this is my file location : C/wamp/www/sitename/web/pdf/它在 Symfony 下,这是我的文件位置:C/wamp/www/sitename/web/pdf/

So I would like my git don't tracked the pdf folder anymore.所以我希望我的 git 不再跟踪 pdf 文件夹。 But I don't know how to do that... sure I can put it into my gitignore... but all the others dev will still have the old one...cause I think gitignore is ignored as well...但我不知道该怎么做……当然我可以把它放到我的 gitignore 中……但所有其他开发人员仍然会有旧的……因为我认为 gitignore 也被忽略了……

Not sure I'm very clear, sorry.不确定我是否很清楚,抱歉。 Don't hesitate to ask what you don't understand in my question.不要犹豫,问你在我的问题中不明白的地方。 Thanks谢谢

You can add a file/folder or a pattern to .gitignore file, and git would never track it. 您可以在.gitignore文件中添加文件/文件夹或模式,而git将永远不会对其进行跟踪。

echo "*.pdf" >> .gitignore # run this command from your project main directory

Otherwise just add *.pyc in the .gitignore file yourself. 否则,您可以自己在.gitignore文件中添加*.pyc

If your file is already tracked then you need to run this command too. 如果您的文件已被跟踪,那么您也需要运行此命令。

git update-index --assume-unchanged <file>

If you want to stop tracking the files, but not delete it from your system: 如果要停止跟踪文件,但又不想从系统中删除它们,请执行以下操作:

Add the folder in your .gitignore . 将文件夹添加到.gitignore

Run this code to keep the files locally and remove the files from your repository. 运行此代码以将文件保留在本地,然后从存储库中删除文件。

git rm -r --cached .

Then: 然后:

git add .

And commit: 并提交:

git commit -m "Remove PDF files"

To work with exact file:要使用精确文件:

  1. Add relative path into .gitignore.将相对路径添加到 .gitignore 中。

git rm --cached <relative path>
git add <relative path>
  1. do commit做提交

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

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