在Git中,有没有一种方法可以获取在合并中丢失的更改。

huangapple go评论71阅读模式
英文:

Is there a way in git to get changes that were lost in a merge

问题

背景:我正在与一个同事合作开展一个项目,这对我们来说是一个庞大的项目,我们已经在此项目上工作了3年。有很多分支用于功能、错误修复、构建等。我认为这是一个相当正常的项目。我们都在不同的分支上开发新功能,完成后将这些更改合并到开发分支。

快进几天,我们正在测试新的应用程序构建时,我们意识到在合并到开发分支时,我意外地覆盖了他在数据库迁移中添加的大约10行代码。

问题:在Git中是否有一种方法可以返回并获取那10行代码并将它们重新引入?

我知道我可以只需回到提交,复制代码并粘贴到新的小分支中,然后合并到开发分支以获取我们需要的内容。但是,将来如果我不小心覆盖了更大的更改,这可能会更复杂,无法通过回滚来获取,因为我们已经远离了原始分支。

英文:

Background : I am working on a project with a coworker, it is a massive project (to us) that we've been working on for the last 3 years. There are a ton of branches for features, bug fixes, builds etc. Pretty normal project I think. We were both working on new features in different branches, finished and merged those changes into the dev branch.

Fast forward a couple of days and we are testing the new application build, we realize that during the merges to dev I accidentally stomped on about 10 lines of code that he had added to a db migration.

Question : Is there a way in git to go back and grab those 10 lines of code and bring them back?

I know I could just go back to the commit, copy the code and paste it where it needs to go in a new small branch and merge it into dev so I have what we need but, for the future if I stomp on larger changes that would be more complicated than just copy paste I would like to know I can get changes back that can't be gotten by rolling back because we progressed too far from the original branch.

答案1

得分: 0

在Visual Studio中,前往Git存储库,然后点击本地历史:

在Git中,有没有一种方法可以获取在合并中丢失的更改。

在DevOps中,前往分支历史,查看分支合并前的历史。你也可以在DevOps中查看特定文件的历史。

英文:

In visual studio go to git repository and click local history:
在Git中,有没有一种方法可以获取在合并中丢失的更改。

In devops, go to branch history and look at the branch pre-merge. You can also look at the specific file history in devops.

huangapple
  • 本文由 发表于 2023年3月7日 23:45:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/75664161.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定