Git:没有添加任何提交但存在未跟踪的文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33513174/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git:nothing added to commit but untracked files present
提问by user4943236
I'm new to Git and is using for the very first time. 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.
我是 Git 的新手,并且是第一次使用。如果有人可以帮助我,我将不胜感激。我尝试在论坛上找到答案,但是出现了大量命令,但不确定该使用哪一个。
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.
我不太确定如何使它工作。如果我删除它们,它将从哪里删除。感谢您的回复。
采纳答案by Tim Biegeleisen
You have two options here. You can either addthe untracked files to your Git repository (as the warning message suggested), or you can addthe 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
之后成功。
回答by Viv
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
回答by Akshay Digrase
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
我认为我们完成了
回答by Zakir Hussain
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
回答by Uriel Hernández
If you have already tried using the git add .
command to add all your untracked files, make sure you're not under a subfolder of your root project.
如果您已经尝试使用该git add .
命令添加所有未跟踪的文件,请确保您不在根项目的子文件夹下。
git add .
will stage all your files under the current subfolder.
git add .
将在当前子文件夹下暂存您的所有文件。