提问人:MohanaSundaram J 提问时间:9/11/2023 最后编辑:SwissCodeMenMohanaSundaram J 更新时间:9/12/2023 访问量:57
在不修改更改列表的情况下在 IntelliJ 中拉取 Git
Git pull in IntelliJ without modifying change list
问:
我在 IntelliJ 中有多个 git 更改列表,现在我需要通过从远程执行 git pull 来更新我的本地代码。但是,我在执行 git pull 时收到一个错误,上面写着“拉取前提交/藏匿”。我可以隐藏我的本地代码,然后拉取,但每当我存储代码时,我的更改列表就会被合并。现在我需要找到一种方法来克服这个问题。如何在 IntelliJ 中执行此操作?
队友将他们的代码推送到远程,现在我在本地设置中需要该代码。
我不能提交我的,因为它没有完全开发,我也无法藏匿,更改列表将被合并。
有没有办法在没有提交或藏匿的情况下进行拉取?或寻找更好的解决方案。
答:
我不能提交我的,因为它没有完全开发
是的,你可以而且应该!
您应该停止使用 git stash,而只是将更改作为正常的普通提交签入 - 尽管将它们标记为临时提交。
TL;博士
替换为 和 。git stash push
git commit -am "==== temp ===="
git stash pop
git reset HEAD^ # On the same branch as you did the temp commit above!
因此,假设您正在处理的分支已命名,并且您当前正在进行一些更改:my_feature_branch
git switch my_feature_branch
git status
git add $...WHATEVER_FILES_ARE_MODIFIED...
git commit -m "==== before pull of teammate's changes ===="
git fetch origin
gitk --all & # Optional, but lets you inspect what the difference between your
# my_feature_branch branch and the new changes from
# origin/my_feature_branch.
git rebase origin/my_feature_branch my_feature_branch
# If any conflicts, use https://github.com/hlovdal/git-resolve-conflict-using-kdiff3
git reset HEAD^ # Undo the earlier temporary commit, bringing you back to where you were,
# but now on top of the newly fetched changes from your teammate.
临时签入内容,然后稍后更改/删除不仅没问题,如果你不这样做,你就没有正确使用 git。git 的初学者有时会害怕签入内容,但这是错误的心态——你应该害怕不签入更改。
(而且可能比您现在更频繁,您距离办理登机手续和回家的时间不应超过 2 分钟)。
此外,您可以开始使用货架而不是储藏。
参见:https://www.jetbrains.com/help/idea/shelving-and-unshelving-changes.html,
您的更改将保存为补丁,并且更改日志将被保留。
评论
git stash
git stash