如何在git中推送新项目,同时忽略远程中的新文件(如自述文件) [英] How to push new project in git, while disregarding new files in remote (like readme)

查看:367
本文介绍了如何在git中推送新项目,同时忽略远程中的新文件(如自述文件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚去了github并创建了一个新项目,到目前为止它只有一个自述文件和gitignore文件。但我有一个项目在本地添加到git中使用

I just went to github and created a new project, so far it only has a readme and gitignore files. But I have a project in local which I added to git using

git init
git add . 
git commit -m "initial commit"
git remote add origin https://github.com/user/repo.git

我想使用 git push -u origin master 推送我的项目,但是收到包含此消息的错误消息

I would like to push my project using git push -u origin master but I get error message containing this

$ git push -u origin master
To https://github.com/user/project.com
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/user/project.com'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

我明白这个错误背后的逻辑,但解决方案是什么?
我不想拉,因为它可能会抹掉我的本地.gitignore文件,是否有没有强制推送忽视这个?

I understand the logic behind this error, but what is the solution? I don't want to pull, as it might erase my local .gitignore file, is there anyway disregard this without force push?

推荐答案

更新:由于某种原因,这个建议从用户的本地文件系统中删除了用户的文件。

update: for some reason this suggestion deleted the user's files from their local filesystem.

在我调查时,我宁愿留下它。 。但我建议你不要按照我的回答。

I prefer to leave it up for now while I investigate... but I recommend you do NOT follow my answer.

这应该有效:

This should work:

git pull (or I prefer git pull --rebase)

<manually resolve any conflicts by editing the text files>

git merge --continue (or git rebase --continue if you used rebase above)

git push

这篇关于如何在git中推送新项目,同时忽略远程中的新文件(如自述文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆