git checkout会删除不应该在那里的文件吗? [英] Will a git checkout delete files that shouldn't be there?

查看:114
本文介绍了git checkout会删除不应该在那里的文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在git中设置了一个post-recieve钩子,比如

 #!/ bin / sh 
GIT_WORK_TREE = / var / www / www.example.org git checkout -f

在服务器上,但不是在我的本地git回购?



如果可以,有什么办法可以阻止它?

解决方案

这取决于文件是否会被删除,取决于它们是否已经存在于存储库中。



如果服务器上的文件(/var/www/www.example.org)会在服务器上的回购站中进行跟踪,但新的结帐包含一项更改,将其删除,然后在服务器端将其删除。



如果服务器上的文件不在服务器上的回购库中跟踪,则它们将保留。因为Git不知道他们。Git不会删除他们。

要告诉他们是否在服务器上被跟踪,你可以执行 git status <有问题的文件> 。如果它说:

 #未记录文件:
#(使用git add< file> ...以包括将承诺的内容)

#<有问题的文件>

然后您知道结帐无法删除。



请注意,如果稍后存在于新的结帐中,则会在下一次结帐时将其移除。


If I set up a post-recieve hook in git like

#!/bin/sh
GIT_WORK_TREE=/var/www/www.example.org git checkout -f

Will that delete files that are on the server but not on my local git repo?

If it will, is there any way to stop that?

解决方案

It depends if the files will be deleted depending if they already existed in the repository prior to the checkout.

If the files that are on the server (/var/www/www.example.org) are tracked in the repo on the server but the new checkout includes a change that removed them then they will be removed on the server side.

If the files that are on the server are NOT tracked in the repo on the server then they will stay. Since Git doesn't know about them Git won't remove them.

To tell if they are tracked on the server you can do git status <file in question>. If it says:

# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       <file in question>

Then you know that a checkout would not remove .

Just take note if later exists in a new checkout than the next checkout which removes would remove it.

这篇关于git checkout会删除不应该在那里的文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆