git 在将更改推送到远程分支时显示所有内容都是最新的

发布于 2024-08-04 07:16:58 字数 354 浏览 11 评论 0原文

我有位于远程存储库(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

辞旧 2024-08-11 07:16:58

根据您的 Git 版本,它可能会尝试推送具有匹配名称的分支,即,将 master 推送到 origin/master 并将 remote_branch 推送到 <代码>origin/remote_branch。如果您的原始存储库没有名为 mybranch 的分支,那么它认为没有任何内容需要更新。

要覆盖此默认值,您可以明确告诉 git 将哪个分支用作源 (mybranch) 以及将哪个分支用作远程存储库上的目标 (remote_branch)

git push origin mybranch:remote_branch

:告诉 git 默认情况下推送到远程跟踪分支的配置选项:

git config --global push.default tracking

我发现这更直观,我认为这是您正在寻找的行为。查看 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 to origin/master and remote_branch to origin/remote_branch. If your origin repository doesn't have a branch named mybranch 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):

git push origin mybranch:remote_branch

There's a config option to tell git to push to remote tracking branches by default:

git config --global push.default tracking

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.

凶凌 2024-08-11 07:16:58

使用最新(2019+)版本的 Git,可以使用 git 来创建分支 (比令人困惑的git checkout更精确)

git switch -c mybranch --track origin/remote_branch

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 confusing git checkout)

git switch -c mybranch --track origin/remote_branch

That way, mybranch is automatically linked to origin/remote_branch, and a simple git push will be enough to push new mybranch commits to origin/remote_branch.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文