【问题标题】:Git branches behaving strangelyGit 分支行为异常
【发布时间】:2023-03-16 23:01:02
【问题描述】:

似乎我无意中修改了我的 git 配置,这样当我从 branchA 切换到 master 时,所有更改都会自动合并到 master。这发生在我没有在 branchA 中提交或我合并到 master 的情况下。过去,如果我在修改跟踪文件后尝试切换分支并且没有提交,我会收到“未提交的更改,无法切换分支”消息,但现在我无法诱导这种行为。我的 git 配置发生了一些变化,但我不知道它可能是什么。有没有人觉得这很熟悉?

非常感谢任何帮助。

Ubuntu 10.10
混帐 1.7.1
github.com

这是我的 git config -l:

giggle.main-window-maximized=false
giggle.main-window-geometry=993x731+318+160
giggle.history-view-vpane-position=223
giggle.main-window-view=HistoryView
giggle.file-view-vpane-position=153
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
remote.origin.url=**************************************
branch.master.remote=origin
branch.master.merge=refs/heads/master
submodule.config/shared_capistrano.url=******************capistrano.git
submodule.vendor/plugins/authentication_client.url=********************.git
branch.dev.remote=origin
branch.dev.merge=refs/heads/dev
branch.1.3.9.remote=origin
branch.1.3.9.merge=refs/heads/1.3.9

【问题讨论】:

  • 您是在谈论您的 未提交 更改被传递到主分支还是其他什么?
  • 您可以通过git config -l 列出您的配置。把它贴在这里(不包括任何秘密),也许有人会发现一些奇怪的东西。
  • 谢谢,是的,这听起来像是我所看到的重复,但我真正的问题是警告信息。我现在明白为什么文件在更改后出现在 master 中,但我仍然不明白为什么我不再收到警告“你有未提交的更改,无法切换分支”。这是一个非常有用的警告。
  • @user508546:如果未提交的更改与目标分支中所做的更改冲突,您只会看到“无法切换分支”消息。 mkdir temp && cd temp && git init && echo foo master1 >foo && git add foo && git commit -mm1 && git branch other && echo foo master2 >>foo && git add foo && git commit -mm2 && git checkout other && echo foo other1 >>foo && git checkout master 产生 error: Your local changes to the following files would be overwritten by checkout: …。如果您从 master 中删除冲突的“m2”,它会起作用:git branch -f master master~ && git checkout master.

标签: git


【解决方案1】:

当您切换分支并且文件仅在本地修改时,Git 不会给您警告/消息(并将更改合并到另一个分支)。例如,您在master 上有您的仓库,创建一个分支temp,对文件进行本地修改。现在,当您切换到master 时,您将不会收到消息。另一方面,如果您在temp 中进行更改并提交它们(即tempmaster 不同)并且然后您有本地修改,它会在您切换时给您该消息给master

【讨论】:

  • 感谢您的回复。更准确地说,这是我的场景:两个分支都存在于远程和本地,所有文件都已被跟踪。我在 branchA 中对跟踪文件进行了更改,然后立即发出“git checkout master”并且没有警告消息,并且更改反映在 master 中。我相信我曾经在这种情况下收到警告,但现在我没有。
猜你喜欢
  • 2017-04-18
  • 2015-10-27
  • 1970-01-01
  • 2021-12-31
  • 2012-09-21
  • 2014-09-08
  • 2011-06-02
  • 1970-01-01
  • 2022-01-09
相关资源
最近更新 更多