简体   繁体   English

如何将特定文件推送到 git 存储库,而本地提交与远程存储库不同步

[英]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.

相关问题 Git推送到远程存储库,丢弃最新提交并替换为本地提交 - Git push to a remote repository, discard the latest commit and replace with local commit 如何使备份git存储库与本地存储库同步,“git push --mirror”或“git remote update” - How to keep a backup git repository in sync with a local one, “git push --mirror” or “git remote update” 当同一分支上有新提交时,自动将本地 git 存储库与远程存储库同步 - automatically sync local git repository with remote repository when there is a new commit on the same branch 如何与远程 Git 存储库同步? - How to sync with a remote Git repository? 如何提交到远程 git 存储库 - How to commit to remote git repository GIT 删除错误提交并推送到远程存储库 - GIT remove the bad commit and Push to the remote repository 何时提交并推送到工作的远程 git 存储库? - When to commit and push to a working remote git repository? 如何在不添加Remote的情况下将提交推送到git存储库? - How to push commit to git repository without adding Remote? 如何将修改后的提交推送到远程 Git 存储库? - How do I push amended commit to the remote Git repository? Git:将本地文件推送到远程存储库中的其他文件名 - Git: Push local file to a different file name in a remote repository
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM