Disclaimer: git is not complicated, it is just universal. Do not be alarmed simply because I made a long answer in a long answer :)
You had:
master: abcdef
and wanted to change c . You made:
* git checkout c (do not check commits in the future. Move the branch head instead)
* changed some files
You are at:
master: abcdef
\ uncommitted-work, detached
If you want to reapply def over your modified "c"
(If you clicked, people located downstream will have to recover from upward adjustment )
git stash .git checkout mastergit stash pop (resolve conflicts)git stage .git commit -m "temporary name for g"- (
master: abcdefg ) git rebase c -i ("reapply my current branch to point c and let me manipulate commits interactively", i.e. rename (rebase) def to new c )- Follow the interactive reboot guide . You want to reorder
g , so after c, change the rebase command from pick to fixup . dd to delete the line, P to place it, i to enter insert mode to enter “fixup”, then :wq to save and exit vim. - (
master: ab-c'-d'-e'-f' , where c' is the result of merging g and c during rebase. def became d'-e'-f' as their origin changed, therefore they are not "" fixed before git, but their contents remain the same)
If you want to undo def (and rewrite history as if you didn’t)
(If you clicked, people located downstream will have to recover from an upward adjustment ):
git stash .git checkout master- (
master: abcdef , with saved files based on c) git reset --hard c (discard all files and write to master with c)- (
master: abc , with saved files) git stash pop (resolve conflicts)- (
master: abc-* ) git stage .git commit -m "description of g"- (
master: abcg )
If you want to undo def (but save them in history)
git stashgit revert --no-commit dgit revert --no-commit egit revert --no-commit fgit pushgit stash pop (there will be no conflicts)git stage .git commit -m "Undo def in order to fix..."git push
If you have git push def and you want to keep them separate:
It looks like your new changes are for a new branch. git branch <foo> .
source share