Changes between Version 3 and Version 4 of GitUsage


Ignore:
Timestamp:
12/05/10 12:55:03 (9 years ago)
Author:
magnate
Comment:

Added tutorial to recover from desync

Legend:

Unmodified
Added
Removed
Modified
  • GitUsage

    v3 v4  
    1818 
    1919If you are a member of "team angband" on github, please read [[Policy/GitMaster]] before making changes to the official angband repo. 
     20 
     21 
     22== So what do I do if I get out of sync with a remote I'm tracking? == 
     23 
     24This typically happens when you're engrossed in working on your commit and haven't noticed that someone else has pushed an update to the branch you're working on in the meantime. So you finish testing your work, commit it and to 'git push remotename branchname', only to get told  
     25 
     26{{{To git@github.com:angband/angband.git 
     27 ! [rejected]        staging -> staging (non-fast-forward) 
     28error: failed to push some refs to 'git@github.com:angband/angband.git' 
     29To prevent you from losing history, non-fast-forward updates were rejected 
     30Merge the remote changes (e.g. 'git pull') before pushing again.  See the 
     31'Note about fast-forwards' section of 'git push --help' for details.}}} 
     32 
     33Argh. You don't want to lose your changes, but you also don't want to do a non-fast-forward merge and risk the wrath of takk ... so try this:  
     34 
     35{{{git fetch remotename 
     36git checkout remotename/branchname 
     37git checkout -b newbranch 
     38git cherry-pick your-commit-id 
     39git push remotename newbranch:branchname}}} 
     40 
     41That creates a new copy of the branch you're tracking, adds your commit without recursing, and pushes it upstream as if you'd done it right in the first place. All that's left is to tidy up your local repo: delete both the old messed-up branch with the right name and the new branch with the wrong name, and re-create the properly-named branch to track the remote one.