简体   繁体   English

Git:没有添加任何提交但存在未跟踪的文件

[英]Git:nothing added to commit but untracked files present

I'm new to Git and is using for the very first time.我是 Git 的新手,并且是第一次使用。 I would appreciate if someone could help me out.如果有人可以帮助我,我将不胜感激。 I tried finding the answer at forums,but there are tons of commands that are coming out and not sure which one to use.我尝试在论坛上找到答案,但是出现了大量命令,但不确定该使用哪一个。

On the prod server, if I do the git pull , it is giving me the following error:在 prod 服务器上,如果我执行git pull ,则会出现以下错误:

Untracked files: (use "git add ..." to include in what will be committed)未跟踪的文件:(使用“git add ...”包含在将提交的内容中)

Optimization/language/languageUpdate.php
email_test.php
nothing added to commit but untracked files present (use "git add" to track)
Please move or remove them before you can merge.

I'm not too sure how to make it work.我不太确定如何使它工作。 If I remove them, from where would it be removed.如果我删除它们,它将从哪里删除。 Appreciate your reply.感谢您的回复。

You have two options here.您在这里有两个选择。 You can either add the untracked files to your Git repository (as the warning message suggested), or you can add the files to your .gitignore file, if you want Git to ignore them.您可以未跟踪的文件添加到您的 Git 存储库(如警告消息建议的那样),或者您可以这些文件添加到您的.gitignore文件中,如果您希望 Git 忽略它们。

To add the files use git add :要添加文件,请使用git add

git add Optimization/language/languageUpdate.php
git add email_test.php

To ignore the files, add the following lines to your .gitignore :要忽略这些文件,请将以下几行添加到您的.gitignore

/Optimization/language/languageUpdate.php
/email_test.php

Either option should allow the git pull to succeed afterwards.任何一个选项都应该允许git pull之后成功。

Also instead of adding each file manually, we could do something like:此外,我们可以执行以下操作,而不是手动添加每个文件:

git add --all

OR或者

git add -A

This will also remove any files not present or deleted (Tracked files in the current working directory which are now absent).这也将删除任何不存在或删除的文件(当前工作目录中的跟踪文件现在不存在)。

If you only want to add files which are tracked and have changed, you would want to do如果您只想添加被跟踪和更改的文件,您会想要做

git add -u

What is the difference between git add . git add .什么区别git add . & git add --all ? & git add --all ?

Please Follow this process请按照此流程

First of all install git bash and create a repository on git首先安装 git bash 并在 git 上创建一个仓库

1) Go to working directory where the file exist which you want to push on remote and create .git folder by 1)转到要远程推送的文件所在的工作目录并通过以下方式创建.git文件夹

$ git init

2) Add the files in your new local repository. 2) 在新的本地存储库中添加文件。

$ git add .

Note: while you are in same folder make sure you have placed dot after command if you putting path or not putting dot that will create ambiguity注意:当您在同一个文件夹中时,如果您放置路径或不放置会产生歧义的点,请确保在命令之后放置点

3) Commit the files that you've staged in your local repository. 3) 提交您在本地存储库中暂存的文件。

$ git commit -m "First commit"**

4) after this go to git repository and copy remote URL 4)在此之后转到git存储库并复制远程URL

$ git remote add origin *remote repository URL

5) 5)

$ git remote -v

Note: this will ask for user.email and user.name just put it as per config注意:这将要求 user.email 和 user.name 只是按照配置

6) 6)

$ git push origin master

this will push whole committed code to FILE.git on repository这会将整个提交的代码推送到存储库上的 FILE.git

And I think we done我认为我们完成了

Follow all the steps.按照所有步骤操作。

Step 1: initialize git第一步:初始化git

$ git init

Step 2: Check files are exist or not.第 2 步:检查文件是否存在。

$git ls

Step 3 : Add the file第 3 步:添加文件

$git add filename

Step 4: Add comment to show第 4 步:添加评论以显示

$git commit -m "your comment"

Step 5: Link to your repository第 5 步:链接到您的存储库

$git remote add origin  "copy repository link  and paste here"

Step 6: Push on Git第 6 步:推动 Git

$ git push -u origin master

If you have already tried using the git add .如果您已经尝试使用git add . command to add all your untracked files, make sure you're not under a subfolder of your root project.命令添加所有未跟踪的文件,确保您不在根项目的子文件夹下。

git add . will stage all your files under the current subfolder.将在当前子文件夹下暂存您的所有文件。

In case someone cares just about the error nothing added to commit but untracked files present (use "git add" to track) and not about Please move or remove them before you can merge.如果有人只关心错误nothing added to commit but untracked files present (use "git add" to track)而不关心Please move or remove them before you can merge. . . You might have a look at the answers on Git - Won't add files?您可能会查看Git上的答案- 不会添加文件吗?

There you find at least 2 good candidates for the issue in question here: that you either are in a subfolder or in a parent folder, but not in the actual repo folder.在那里,您至少可以找到 2 个适合该问题的候选者:您要么在子文件夹中,要么在父文件夹中,但不在实际的 repo 文件夹中。 If you are in the directory one level too high, this will definitely raise that message "nothing added to commit…", see my answer in the link for details.如果您在目录中的级别太高,这肯定会引发消息“没有添加任何内容...”,有关详细信息,请参阅我在链接中的回答。 I do not know if the same message occurs when you are in a subfolder, but it is likely.我不知道当您在子文件夹中时是否会出现相同的消息,但很有可能。 That could fit to your explanations.这可能符合您的解释。

暂无
暂无

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

相关问题 Git 没有向提交添加任何内容,但存在未跟踪的文件 - 即使将这些文件添加到 gitignore - Git nothing added to commit but untracked files present - even with those files added to gitignore Git-列出根目录中的每个文件后,“没有添加任何内容来提交但存在未跟踪的文件” - Git - “nothing added to commit but untracked files present” after listing every file in root npm-debug.log位于.gitignore文件中,但我仍然收到消息“没有添加任何内容来提交但存在未跟踪的文件(使用” git add”进行跟踪)” - npm-debug.log is in .gitignore file, but I still get the messsage “nothing added to commit but untracked files present (use ”git add“ to track)” Git commit -a “未跟踪的文件”? - Git commit -a “untracked files”? git commit显示未跟踪的文件 - git commit shows untracked files git checkout HEAD〜2(示例)将删除未跟踪的文件(如果它们是在上次提交时添加的) - git checkout HEAD~2 (example) deletes untracked files if they were added with last commit Git:提交修改/未跟踪文件的子集 - Git: Commit a subset of modified/untracked files 如何添加未跟踪的文件在git中提交? - How to add untracked files to commit in git? Git-使用签出提交ID获取未跟踪的文件 - Git - Get untracked files with checkout commit id git:如何忽略所有存在的未跟踪文件? - git: How to ignore all present untracked files?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM