git 在将更改推送到远程分支时显示所有内容都是最新的
我有位于远程存储库(origin/master)中的提交,我想将其放入从该存储库(origin/remote_branch)创建的分支中。
当我签出该远程分支时
git checkout -b mybranch origin/remote_branch
,然后挑选我所做的提交,
git cherry-pick 9df63616b0428cf6edc4261adb533a1ac516b9a0
当我尝试推送时,git 会说一切都是最新的。
git push
我做错了什么吗?
i have commits that are in a remote repository (origin/master) which i want to put in a branch created from that repository (origin/remote_branch).
when i checkout to that remote branch
git checkout -b mybranch origin/remote_branch
then cherry-picked the commits that i made
git cherry-pick 9df63616b0428cf6edc4261adb533a1ac516b9a0
git says everything-up-to-date when i try to push.
git push
is there anything i'm doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据您的 Git 版本,它可能会尝试推送具有匹配名称的分支,即,将
master
推送到origin/master
并将remote_branch
推送到 <代码>origin/remote_branch。如果您的原始存储库没有名为mybranch
的分支,那么它认为没有任何内容需要更新。要覆盖此默认值,您可以明确告诉 git 将哪个分支用作源 (
mybranch
) 以及将哪个分支用作远程存储库上的目标 (remote_branch
):告诉 git 默认情况下推送到远程跟踪分支的配置选项:
我发现这更直观,我认为这是您正在寻找的行为。查看 git config 手册页 中的
push.default
选项。另请查看 git Push 手册页 查看如何覆盖默认行为。Depending on your version of Git, it may be trying to push branches with matching names, i.e.,
master
toorigin/master
andremote_branch
toorigin/remote_branch
. If your origin repository doesn't have a branch namedmybranch
then it thinks there's nothing to update.To override this default, you can explicitly tell git which branch to use as the source (
mybranch
) and which to use as the destination on the remote repository (remote_branch
):There's a config option to tell git to push to remote tracking branches by default:
I find this more intuitive and I think it's the behavior you're looking for. Checkout the
push.default
option in the git config man page. Also checkout the Examples section in the git push man page to see how to override the default behavior.使用最新(2019+)版本的 Git,可以使用
git 来创建分支
(比令人困惑的git checkout
更精确)switch 这样,
mybranch
会自动链接到origin/remote_branch
,并且简单的git push
就足以推送新的mybranch
> 提交到origin/remote_branch
。With a recent (2019+) version of Git, creating a branch would be done with
git switch
(more precise than the confusinggit checkout
)That way,
mybranch
is automatically linked toorigin/remote_branch
, and a simplegit push
will be enough to push newmybranch
commits toorigin/remote_branch
.