git重置提交和推送问题

发布于 2024-12-28 06:57:22 字数 427 浏览 1 评论 0原文

最近,我的团队中发生了一个新人尝试进行 git pull 的事情。系统上出现了一些冲突,之后开发人员只需执行 git 重置(将索引带到最后一个 HEAD)。然后,开发人员“提交”了一个文件更改并将其推送到远程。当然,很多改变都丢失了。

然而,我们花了相当长的时间才弄清楚是谁做了错误的更改(以及哪个提交是错误的提交),并且恢复它需要付出很多不同的努力。现在在 git 历史记录中(使用 gitk 或 git log)git 只显示已提交的文件,但这是覆盖以前文件的情况(我知道这个概念更多的是 CVS 而不是 git,在这种情况下文件已移动到以前的提交)。在这种情况下,最好的调试策略是什么?

一旦我们知道哪个分支违规了,一旦我在好提交和坏提交之间进行 git diff,我就可以看到文件列表,但仅查看特定提交,我们能否找出哪些文件已移动到上一个提交。

如果问题没有完全弄清楚,我们深表歉意。

Recently it happened in my team that a fresher tried to do a git pull. Some conflicts appeared on the system after which the developer simply did a git reset (bringing the index to last HEAD). Then the developer "committed" one file change and pushed it to remote. Naturally quite a lot of changes were lost.

However it took us quite some time to figure out who did the bad change (and which commit was bad commit) and recovering it was a whole lot of different effort. Now in the git history (using gitk or git log) git only shows what files have been committed but this is case of overwriting previous files (I know this concept is more of CVS not git in which case files have been moved to a previous commit). What is the best strategy to debug in this case?

Once we know which branch is offending one, once I do a git diff between good and bad commit I can see list of files but looking at the particular commit only, can we find out what files have been moved to a previous commit.

Apologies if the problem is not entirely clarified.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

情魔剑神 2025-01-04 06:57:22

查看 git log -pbranch-in-question 的输出,您将看到逐个文件所做的更改。您现在可以通过执行 git checkout来采取相应的行动-- 一些文件 使分支再次正常。添加所有更改并提交和推送。从现在开始你应该好好的。

Take a look at the output of git log -p branch-in-question and you will see changes made, file by file. You can now act accordingly by doing git checkout <some commit> -- some files to get the branch straight again. Add all the changes and commit and push. You should be good from here on.

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