git - 在推送后恢复空的 merge 提交

标签 git github git-merge

我采取的步骤:

  1. 将 master 分支 merge 到我的 feature 分支。
  2. 开始解决提交,不小心在其中一个冲突中使用他们的解决方案,并想重做。
  3. 重置所有更改。
  4. 此时我似乎无法做任何事情,因为我处于 merge 状态,我不小心提交了这些更改并推送到 GitHub(我使用了 SourceTree 并勾选了该选项!)

现在,每当我尝试从 master merge 时,它都会假设我已经有了最新的更改,并且没有任何内容添加到我的功能分支。

我尝试运行 git revert -m 1 <commit hash of the empty commit>但我得到了:

On branch feature/profile_page
Your branch is up-to-date with 'origin/feature/profile_page'.
nothing to commit, working tree clean

然后我尝试恢复之前的更改,它确实有效,但现在本地是 GitHub 上功能分支后面的一次提交。

有什么想法吗?

这是我的日志:

* ff46aa6 (HEAD -> feature/profile_page, origin/feature/profile_page) Revert     "Added link to user profile page in MainMenu"
*   64e96b3 .
|\  
| * 9c023f5 (origin/master, origin/HEAD, master) Made the delete button invoke a pop-up which can delete the responders.
| * 87a028c Added a placeholder page that can be used to link to, or navigate from when you need a placeholder page.
| * 6ae954d Added the ResponderGroupPage and new delete icon.
| * 752fb83 Updated the layout to closer match the mock-up
| * 55e8c29 Added missing schedule icon
| * 6255338 Tweaks to make the page work/look correct on iOS
| * 178beb1 Update to the IncidentHistoryPage so that it displays a history of an event as a list under your selected item when you select one.
| * 5bfbbf1 Added titles to pages and button to link to IncidentHistoryPage.
| * 4570346 Added basic IncidentHistoryPage using mock data
* | 663a378 Added link to user profile page in MainMenu
* | 123da81 Added EditProfilePasswordPage and CloseAccountPage
* | 40a00ea Added change phone number page
* | b80f9af Added Change email page
* | 8a3710a Added MySubscriptions Page
* | 3c8ddee Added MyAccountPage
* | dd4fa9e ImageWithPopupMenu handles events
* | cbfae5f Added ImageWithPopupMenu
* | 304dd5c .
* | b730e7f EditProfilePage first pass
* | 0ac9603 Added UserProfile view model
* | af7f6ed .
* | 5f4e0c0 Profile Page first pass
| | * bbbbc4d (origin/feature/api_hooks) Setting up a wearer after activating a device will now associate the wearer with the device. Added WearerDataStore which will retrieve and manage the wearer list shown on the home screen.
| | * 45b3639 App will now check if a user is currently logged in when it launches.     - If there is currently an active session, which is not authenticated with the API key, then the app will navigate to the home screen instead of landing.
| | * 88250f5 Sign in page now using Bindings with view model for the entry text. Sign in page now using localisation. Added api calls to sign up process. Added validation to the sign up process for checking email address and phone numbers.
| |/  
| *   2590342 Merge branch 'master' of https://github.com/FirstAppLtd    /Watchie_Xamarin
| |\  
| | * 4e13537 Added the EditSafezonePage and placeholder pop-ups for CALL/RAISE SOS on the Homescreen and Wearer Profile screens.
| | *   ee1a2dc Merge branch 'master' into hockeyapp_integration
| | |\  
| | | * 7f1d961 New icon paths
| | * |   3d05a1f Merge branch 'master' into hockeyapp_integration
| | |\ \  
| | | |/  
| | | *   66d6303 Reworked the Homescreen so that it works on iOS as the list view didn’t work correctly. I moved the Icons on iOS into the root resources so that they can be indexed in the same way as on Android to avoid any needing to do #ifIOS look here.
| | | |\  
| | | | * d7e2d63 (origin/UpdatingIcons) Fix for the Homescreen so that it displays correctly on iOS. Moved where the iOS icons are stored so that they can be referenced exactly like the Android assets.
| | | | * 5d6846a New branch updating the icons
| | * | | a8d3ddc Set Android HockeyAppId
| | * | | df479a2 Set iOS HockeyAppId
| | * | | d0c820d Integrated HockeyAppId from info.plist. Disabled AuthenticateInstallation call for current config.
| | * | | d0702fe Added iOS HockeyApp to the Info.plist file
| | * | | 05f627a Refactored the HockeySDK App ID to the AssemblyInfo file for Android
| | * | | f99cf8e Added HockeySDK update to Android
| | * | | d0c94d0 Added ability to enable HockeySDK User metrics in Android
| | * | | 2b14729 Disabled HockeySDK for iOS
| | * | | 32fa935 Integrated HockeySDK for Android to detect crashes
| | * | | 58017a5 Added HockeySDK NuGet package to Android solution

最佳答案

根据您的日志,我认为最干净的解决方案是:

git checkout 663a3784ab82f019996a5091f3dfb2401c0403b5 -b feature_clean

这会将您标记为“有效”(在您的编辑之前)的 merge 之前的提交 checkout 为新分支“feature_clean”。然后你可以执行 merge (git merge master)并确保它是干净的。最终,您可以用 feature_clean 替换功能,例如删除前者并重命名后者:

git branch -d feature # delete old branch
git branch -m feature_clean feature # rename clean branch
git push -f # force push feature to rewrite history on remote

我不建议 git reset 663a37... --hard 后跟强制推送的原因是这样你可以保留“损坏”的分支并可以执行 git checkout 663... 解决冲突所需的频率。

希望对您有所帮助。

关于git - 在推送后恢复空的 merge 提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45506782/

相关文章:

linux - 如何在我的 bash PROMPT 中为当前的 git 分支添加颜色?

git - 错误 : RPC failed; result=55, HTTP 代码 = 0 增加缓冲区没有成功

git - Docker 构建推送操作 "Not a valid object name";输出 repo 的所有分支和标签

c++ - 始终使用 Visual Studio 中可用的最新工具集

security - 如何通过 Github Webhooks 安全地加密 secret ?

jquery - 使用 jQuery.ajax() 保存匿名 github 要点

github - 如何在 GitHub 上进行快进合并?

git - 以下 Git 提交策略正确吗?

git - 如何摆脱 git 分支/pull 请求中不需要的更改?

git - 这是使用 git push --force 的好方案吗?我可以在这种情况下使用它吗?