Changes between Version 3 and Version 4 of GitUsage

12/05/10 12:55:03 (8 years ago)

Added tutorial to recover from desync


  • GitUsage

    v3 v4  
    1919If you are a member of "team angband" on github, please read [[Policy/GitMaster]] before making changes to the official angband repo. 
     22== So what do I do if I get out of sync with a remote I'm tracking? == 
     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  
     27 ! [rejected]        staging -> staging (non-fast-forward) 
     28error: failed to push some refs to '' 
     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.}}} 
     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:  
     35{{{git fetch remotename 
     36git checkout remotename/branchname 
     37git checkout -b newbranch 
     38git cherry-pick your-commit-id 
     39git push remotename newbranch:branchname}}} 
     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.