Search code examples
gitversion-controlbitbucketsmartgit

Get working code back but maintaining a few changes


I have a repository with two branch: master and development. Recently I added some code to development which broke my entire working site but in this same commit & push I fix a lot of things too. Is there any way to come back to working code but maintaining those fixes that work? I use SmartGit on Windows 7, the repos are hosted at Bitbucket.

Add some extra information around SmartGit Logs

enter image description here


Solution

  • Approach 1 (many or already pushed commits)

    Using SmartGit's Log window, select the offending commit and invoke Revert.

    Approach 2 (few and only local commits)

    If the numbers of affected commits is small and all of them are not yet pushed, I would recommend to re-create development using SmartGit's Log window:

    (1) Checkout the last known good commit on development. When doing so, SmartGit will ask you whether to create a new branch: confirm this and create e.g. development-2.

    (2) Cherry-Pick all good commits from development to development-2. If there are conflicts, switch to the Main window and fix them in your working tree.

    (3) Use Add Branch and (re-add) development to your current HEAD commit, i.e. development will be identical to development-2 afterwards.

    (4) Check Out development again and finally Delete development-2.