[英]How to push a particular file to git repository, while the local commit is not in sync with remote repository
I was trying to push a file from my local git repository to central git repository.我试图将文件从本地 git 存储库推送到中央 git 存储库。 As my local repository is not in sync with central remote repository, I am unable to push the file.由于我的本地存储库与中央远程存储库不同步,我无法推送文件。 My code requirement is that I can't 'git pull' the repository.我的代码要求是我不能 'git pull' 存储库。 I need to do a 'git push' on only one file, without doing a 'git pull'.我只需要对一个文件执行“git push”,而不需要执行“git pull”。 Is it possible to do so?有可能这样做吗?
Your code "requirement" is off-kilter.您的代码“要求”不合时宜。 If you are behind the remote repository, you should be doing a git pull
to sync up before attempting to push your local branch.如果您在远程存储库后面,则应该在尝试推送本地分支之前执行git pull
以同步。 Your options are:您的选择是:
git pull origin yourBranch
or或者
git pull --rebase origin yourBranch
The first option will update your remote tracking branch origin/yourBranch
with whatever is on the remote and attempt to merge it into your local branch.第一个选项将使用远程上的任何内容更新您的远程跟踪分支origin/yourBranch
并尝试将其合并到您的本地分支中。 The second option will also update the remote tracking branch, but will instead rebase your local branch on the remote.第二个选项也将更新远程跟踪分支,而是将重订遥控器上的当地分行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.