简体   繁体   English

如何将新文件添加到我的 Git 存储库?

[英]How can I add a new file to my Git repository?

I'm creating some new files and am trying to add them but when I use git add applications/libraries/calendarclass.php , it won't recognize that I have a file there我正在创建一些新文件并尝试添加它们,但是当我使用git add applications/libraries/calendarclass.php时,它不会识别出我在那里有文件

I just created that file in textmate and am staring at it.我刚刚在 textmate 中创建了该文件并正在盯着它看。 How do I add it to git?如何将其添加到 git?

releventz$ git add application/libraries/calendarclass.php
fatal: pathspec 'application/libraries/calendarclass.php' did not match any files
releventz$ ls
application css     index.php   license.txt
authnet     images      js      system
releventz$ cd application
application$ ls
cache       controllers errors      hooks       language    logs            third_party
config      core        helpers     index.html  libraries   models          views
application$ cd libraries
libraries$ ls
MY_Unit_test.php    index.html      loginclass.php
libraries$ git branch
* master
libraries$ git add calendarclass.php
fatal: pathspec 'application/libraries/calendarclass.php' did not match any files

When I use git status当我使用git status

libraries$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 2 commits.
#
nothing to commit (working directory clean)

After adding your new file, type:添加新文件后,键入:

git status

You should then see the file ready to be added - then either type git add (filename) or git add.然后您应该看到准备添加的文件 - 然后键入git add (filename)git add. if you want to add all of them.如果你想添加所有这些。

If touch ing the file doesn't do the trick, you may need to take a look at your .gitignore to make sure there's no funny business going on in there, like an exclude all or anything similar.如果touch文件不起作用,您可能需要查看您的.gitignore以确保其中没有发生有趣的事情,例如 exclude all 或任何类似的事情。

From your output, it looks like calendarclass.php doesn't exist.从您的 output 看来, calendarclass.php不存在。 If you want to create the file, then add it to git, do:如果要创建文件,然后将其添加到 git,请执行以下操作:

touch calendarclass.php
git add calendarclass.php

Remove whitespaces from the tail of your filename.从文件名的尾部删除空格。

It looks like calendarclass.php does not exist to add it, and it seemed you have not modified your code after last commit that's why there are no unstaged nor staged files, may be you merged from another branch into master locally, that's why it says it is ahead of 'origin/master' by 2 commits.它看起来像 calendarclass.php 不存在添加它,并且似乎您在上次提交后没有修改您的代码,这就是为什么没有未暂存或暂存文件的原因,可能是您从另一个分支合并到本地 master,这就是它说的原因它领先于 'origin/master' 2 个提交。

I bet your calendarclass.php is not noticed by git because of a rule in a.gitignore file.我敢打赌,由于 a.gitignore 文件中的一条规则,git 不会注意到您的 calendarclass.php。 Remove that rule and you will be able to add the file.删除该规则,您将能够添加该文件。

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

相关问题 我已经在计算机上重新安装了Git。 。 。 不能将文件添加到新的本地.git存储库 - I have reinstalled Git on my computer . . . and can NOT add files to my new local .git repository 如何使用 SourceTree 在我的 git 存储库中找到文件? - How can I find a file in my git repository with SourceTree? 如何通过 git 补丁添加新的 git 存储库文件 - How to add new git repository file thru git patch 如何在git中添加另一个存储库? - How can I add another repository in git? 如何在我的存储库中保持另一个git存储库中文件的最新状态? - How can I keep a file in another git repository up to date in my repository? 如何将 .git 目录添加到 git 存储库? - How can I add a .git directory to a git repository? 如何将文件从本地计算机添加到已克隆的本地git存储库中? - How do I add a file from my local machine to a local git repository that I have cloned? 无法将原点添加到新的git存储库 - Cannot add origin to my new git repository 如何将没有git历史记录的项目的当前状态推送到新的远程存储库? - How can I push the current state of my project, without git history, to a new remote repository? 从github提取新版本时,如何丢弃Git存储库中的本地更改? - How can I throw away local changes in my Git repository when pulling a new version from github?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM