运行 git pull origin master 时出错
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4779715/
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
Error when running git pull origin master
提问by Aditya Hadi
I'm a newbie in using git version control, I got this error when running git pull origin master
, this is the error :
我是使用 git 版本控制的新手,运行 git 时出现此错误pull origin master
,这是错误:
From /opt/mygit/abc
* branch master -> FETCH_HEAD
error: Untracked working tree file 'nbproject/private/rake-d.txt' would be overwritten by merge. Aborting
Am I miss something? thanks in advance. :D
我错过了什么吗?提前致谢。:D
回答by Sebastian Paaske T?rholm
It would appear that you have the file nbproject/private/rake-d.txt
in your local repository, but not tracked by git.
看起来您nbproject/private/rake-d.txt
在本地存储库中有该文件,但没有被 git 跟踪。
Meanwhile, it has been added to the remote repository since your last pull, so doing a pull would overwrite that file, and thus git is warning you that that would happen and aborting the pull.
同时,自您上次拉取后,它已被添加到远程存储库中,因此执行拉取操作会覆盖该文件,因此 git 会警告您会发生这种情况并中止拉取操作。
To resolve this, you'll need to go and either delete or rename the file.
要解决此问题,您需要删除或重命名文件。
If you want to automate this, run a git clean
to clean out the folder of untracked files (that is, delete them). It might be a good idea to run git clean -n
first, though, which merely lists the files it's going to delete, letting you see if there's anything important it plans on deleting.
如果要自动执行此操作,请运行 agit clean
清除未跟踪文件的文件夹(即删除它们)。git clean -n
不过,首先运行可能是个好主意,它仅列出要删除的文件,让您查看是否计划删除任何重要的文件。
Alternatively, you could add the file to the repository (remember to commit it), and then pull. git will then try to merge your local copy with the remote one.
或者,您可以将文件添加到存储库(记得提交),然后拉取。然后 git 将尝试将您的本地副本与远程副本合并。
回答by Aditya Hadi
You could use first
你可以先用
git clean -f -d
(or git reset --hard HEAD ) to clean your untracked files then do a
(或 git reset --hard HEAD )清理未跟踪的文件,然后执行
git pull
Keep in mind this will delete any untracked files
请记住,这将删除任何未跟踪的文件
回答by Aditya Hadi
if you are getting the pulling error due to untracked worked....
try it...
go to your project location
$ cd /usr/local
$ git fetch origin
$ git reset --hard origin/master
回答by ritesh9984
If you are newly started git then follow these steps :
如果您是新开始的 git,请按照以下步骤操作:
Let's suppose your git repository url is https://github.com/absuser/repo.git
假设您的 git 存储库 url 是https://github.com/absuser/repo.git
And you want to push your project on this repository with branch name 'testbranch' and your code on your machine at '/home/ubuntu/Documents/code'
并且您想使用分支名称“testbranch”将您的项目推送到此存储库上,并将您的代码推送到您机器上的“/home/ubuntu/Documents/code”
Now let's start :
现在让我们开始:
press ctrl+alt+T to open your terminal.
按 ctrl+alt+T 打开终端。
$ cd /home/orange/Documents/code
$ git init
Create branch on local $ git checkout -b testbranch
在本地创建分支 $ git checkout -b testbranch
Add remote repository $ git remote add origin https://github.com/absuser/repo.git
添加远程仓库 $ git remote add origin https://github.com/absuser/repo.git
Verify added remote $ git remote -v
验证添加的远程 $ git remote -v
$ git config --global user.email "[email protected]"
$ git config --global user.name "username"
$ git add .
$ git commit -m "my first comit "
$ git push origin testbranch
Now your code pushed on git now .
现在你的代码现在推送到 git 上。
In case if someone else also committed the code on same branch and you want to merge all the changes with your code on your local machine and push to git then follow these steps :
如果其他人也在同一分支上提交了代码,并且您想将所有更改与本地计算机上的代码合并并推送到 git,请按照以下步骤操作:
First you have to stagged your all updated files .
首先,您必须标记所有更新的文件。
$ git add .
$ git pull origin testbranch
If any conflict occurs then resolved that and do following steps
如果发生任何冲突,则解决该冲突并执行以下步骤
$ git add .
otherwise go ahead
否则继续
$ git commit -m 'merged changes from master'
$ git push origin testbranch
回答by hd1
It would appear that you're using NetBeans for development here. I generally add such IDE-specific objects to .gitignore.
看起来您在这里使用 NetBeans 进行开发。我通常将此类特定于 IDE 的对象添加到 .gitignore。
回答by Smoke
What you need to do is remove the local untracked copy. What's happening is that a file exists remotely, but not locally. git will not allow you to overwrite a local untracked file.
您需要做的是删除本地未跟踪的副本。发生的情况是文件远程存在,但不在本地。git 不允许您覆盖本地未跟踪的文件。
you have to use ctrl+shift+F10
its useful
你必须使用ctrl+shift+F10
它的有用