简体   繁体   English

Git repo 没有 .htaccess 文件,如何创建不会被 git pull --rebase 删除的本地 .htaccess

[英]Git repo does not have a .htaccess file, how do I create a local .htaccess that will not be removed by git pull --rebase

The title might be a bit weird explanation of things so I will go into more detail here.标题可能对事物的解释有点奇怪,所以我将在这里更详细地介绍。

I have set up git repo trough github for a website so all of us can edit on our own computers and then push changes to the webserver.我已经通过 github 为网站设置了 git repo,这样我们所有人都可以在自己的计算机上进行编辑,然后将更改推送到网络服务器。 I then have a pull script on my website that does git pull --rebase every few minutes, if there are changes in the repo.然后我的网站上有一个 pull 脚本,它每隔几分钟git pull --rebase一次git pull --rebase ,如果 repo 有变化。

Now, I do not wish to have the username and password for the database on github, so I was thinking of having a .htaccess file locally on the server that holds the username and password instead of having it in the php files.现在,我不希望在 github 上拥有数据库的用户名和密码,所以我想在服务器上本地有一个 .htaccess 文件来保存用户名和密码,而不是将它放在 php 文件中。 So I created a .htaccess file locally, and added .htaccess in gitignore and gitattributes, but whenever I do a git pull --rebase the updates to the .htaccess file are removed.所以我在本地创建了一个 .htaccess 文件,并在 gitignore 和 gitattributes 中添加了 .htaccess,但是每当我执行git pull --rebase ,对 .htaccess 文件的更新都会被删除。 And if I do git rm .htaccess and git status it says that .htaccess has been deleted and that I have to push the file to the repo, even though the repo does not have any .htaccess file.如果我执行git rm .htaccessgit status它说 .htaccess 已被删除并且我必须将文件推送到 repo,即使 repo 没有任何 .htaccess 文件。 And I can't push either because the server version of the repo is read-only.而且我也无法推送,因为 repo 的服务器版本是只读的。

Any ideas?有任何想法吗?

Update with .gitignore file: ################# ## Eclipse #################用 .gitignore 文件更新:##################Eclipse #################

*.pydevproject
.project
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch

# CDT-specific
.cproject

# PDT-specific
.buildpath


#################
## Visual Studio
#################

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.suo
*.user
*.sln.docstates

# Build results
[Dd]ebug/
[Rr]elease/
*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.vspscc
.builds
*.dotCover

## TODO: If you have NuGet Package Restore enabled, uncomment this
#packages/

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf

# Visual Studio profiler
*.psess
*.vsp

# ReSharper is a .NET coding add-in
_ReSharper*

# Installshield output folder
[Ee]xpress

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish

# Others
[Bb]in
[Oo]bj
sql
TestResults
*.Cache
ClientBin
stylecop.*
~$*
*.dbmdl
Generated_Code #added for RIA/Silverlight projects

# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML



############
## Windows
############

# Windows image file caches
Thumbs.db

# Folder config file
Desktop.ini


#############
## Python
#############

*.py[co]

# Packages
*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg

# Installer logs
pip-log.txt

# Unit test / coverage reports
.coverage
.tox

#Translations
*.mo

#Mr Developer
.mr.developer.cfg

# Mac crap
.DS_Store

#################
## Project specific
#################

# Ignore htcaccess so so pwd is not public
.htaccess

# Ignore the pull script because this is only for the server
pull.php

I managed to find a solution (I hope) from this post on stackoverflow: Ignore files that have already been committed to a Git repository我设法从 stackoverflow 上的这篇文章中找到了一个解决方案(我希望): 忽略已经提交到 Git 存储库的文件

And the line that did it for me was: git update-index --assume-unchanged <file>为我做的那一行是: git update-index --assume-unchanged <file>

Github just doesn't support uploading the htacess file, but you can still add the htaccess file manually in github Github只是不支持上传htacess文件,但是你仍然可以在github中手动添加htaccess文件

1. Go to the repository where you want to add the htacess file 1.进入你要添加htacess文件的仓库

2. Click Add file - Create new file 2. 点击Add file - Create new file

3. Open your file .htaccess and copy all the contents of your htaccess file and paste it into the 'Edit new file' section. 3. 打开文件 .htaccess 并复制 htaccess 文件的所有内容并将其粘贴到“编辑新文件”部分。 All you have to do is enter the file name .htaccess , enter the commit name as you wish and then commit您所要做的就是输入文件名.htaccess ,根据需要输入提交名称,然后提交

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

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