GIt状态说文件被删除

GIt状态说文件被删除

本文介绍了GIt状态说文件被删除,但git rm说errror:pathspec'.....'与任何文件都不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经完成了这100次。
我从一个目录中删除了一个文件,然后运行git status,这看起来很好。

 #没有为commit提交的更改:
#(使用git add / rm< file> ...更新将要提交的内容)
#(使用git checkout - < file> ...更改工作目录)

#deleted:themes / custom / gitb / templates / views-view-field - field-overall-rating.tpl.php

然后运行
git rm themes / custom / gitb / templates / views-view-field --field-overall-rating.tpl.php
并收到错误消息

 错误: pathspec'themes / custom / gitb / templates / views-view-field-field-overall-rating.tpl.php'与git已知的任何文件都不匹配。 

git status知道这个文件,但是git rm不会并且不会删除它。我被卡住了,我该如何解决这个问题?

解决方案
一个快速和肮脏的解决方案是加回文件并使用

  git rm themes / custom / gitb / templates / views-view-field  -  field-overall-rating.tpl.php 

将其移除。



git rm 也会从文件系统中删除文件,所以你不需要(通常你不应该)手动删除文件。

编辑

更简单的方法是制作git使用

  git add -u 


  git commit -a 

$ b

git-add 的文档中,以下是<$ c


以下是 -a 中的一个。 code> git-commit


I've done this 100s of times. I deleted a file from a directory and then run git status which looks fine.

# Changes not staged for commit:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   deleted:    themes/custom/gitb/templates/views-view-field--field-overall-rating.tpl.php
#

Then I rungit rm themes/custom/gitb/templates/views-view-field--field-overall-rating.tpl.phpand receive an error message

error: pathspec 'themes/custom/gitb/templates/views-view-field--field-overall-rating.tpl.php' did not match any file(s) known to git.

git status "knows" about the file but but git rm doesn't and won't remove it. I'm stuck and how do I solve this?

解决方案

A quick and dirty solution would be to add back the file and use

git rm themes/custom/gitb/templates/views-view-field--field-overall-rating.tpl.php

to remove it.

git rm removes the file from the filesystem too, so you don't need (and in general you shouldn't) to manually remove the file.

EDIT

A cleaner way to do so, would be to make git to notice the missing file using

git add -u

or

git commit -a

From the doc of git-add, here's the description of the -u option

and here's the one for the -a option of git-commit

这篇关于GIt状态说文件被删除,但git rm说errror:pathspec'.....'与任何文件都不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 08:25