配置文件已经在远程git存储库中.想要unversion而不是删除.怎么样?

mar*_*say 4 git version-control github

我和我的朋友选择使用git和GitHub进行项目合作.我们都是新手.

我的朋友用他的项目配置文件的版本初始提交了我们的项目文件.我的配置文件会有所不同.我们不希望来回发送这些文件的更改.

我已经发布git init并将git pull git@github.com:my_friend/our_repository.git master我们的项目文件放到我的开发服务器上.

然后.gitignore我在我的开发服务器上的项目根目录中创建了一个文件(我在那里git init):

# this is .gitignore in the project's root directory
index.php
config/some_config_file.php
config/another_config_file.php
Run Code Online (Sandbox Code Playgroud)

由于这些配置文件已经存储在存储库中,因此这些行.gitignore不会执行任何操作.我理解这一点.其他SO答案建议这些命令:

git rm --cached index.php
git rm --cached config/some_config_file.php
git rm --cached config/another_config_file.php
git commit -m "hope this works"
git push 
Run Code Online (Sandbox Code Playgroud)

但这删除了远程GitHub存储库中的这些文件!不好.我希望这些文件保留在GitHub上,这样它就不会报警我的朋友.我只想在我的开发服务器上保留我自己的无版本文件副本,而不管GitHub存储库中发生了什么.

如何使用git实现此设置?

jwe*_*ich 5

你不能这样做,但你可以告诉git忽略对这些文件的进一步(本地)更改.尝试:

git update-index --assume-unchanged <your_file>
Run Code Online (Sandbox Code Playgroud)