Changes between Version 4 and Version 5 of GitUsage
- Timestamp:
- 12/05/10 12:55:37 (9 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
GitUsage
v4 v5 24 24 This 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 25 26 {{{To git@github.com:angband/angband.git 26 {{{ 27 To git@github.com:angband/angband.git 27 28 ! [rejected] staging -> staging (non-fast-forward) 28 29 error: failed to push some refs to 'git@github.com:angband/angband.git' 29 30 To prevent you from losing history, non-fast-forward updates were rejected 30 31 Merge 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 'Note about fast-forwards' section of 'git push --help' for details. 33 }}} 32 34 33 35 Argh. 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 36 35 {{{git fetch remotename 37 {{{ 38 git fetch remotename 36 39 git checkout remotename/branchname 37 40 git checkout -b newbranch 38 41 git cherry-pick your-commit-id 39 git push remotename newbranch:branchname}}} 42 git push remotename newbranch:branchname 43 }}} 40 44 41 45 That 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.