18
loading...
This website collects cookies to deliver better user experience
git checkout feature2
.git reset --soft HEAD~
- move back one commit and keep your changesgit reset --hard HEAD~
- move back one commit and discard all changesgit add
- add the missing/modified file(s) you forgot to addgit commit --amend --no-edit
- alter the previous commit (remove --no-edit
if you want to modify the commit message)git branch feature3
- create a new branch at your current positiongit reset HEAD~ --hard
- take back master to the previous commitgit checkout feature3
- switch to your new branchgit reset HEAD~ --soft
- take yourself back to the previous commit and keep your changesgit stash
- stash your changes so we can switch branchesgit checkout feature2
- switch to another branchgit stash pop
- unpack your changes from stashgit add .
- add your files and commit them normallygit commit -m "fixed"
git log
- find the hash of that commit you want to revertgit revert <hash>
$ git checkout c5b64
Note: checking out 'c5b647'.
You are in 'detached HEAD' state...
git checkout master
. Clearly we now know, git checkout master
in its most basic form is like saying "Go ahead and just point to master".git reflog
is coming for rescue.$ git reflog
5b35f6d HEAD@{1}: pull ...
ca92d15 HEAD@{2}: ...
759dab1 HEAD@{3}: commit (merge): ...
065e269 HEAD@{4}: commit: ...
f357606 HEAD@{5}: commit: ...
9u7b45 HEAD@{6}: checkout: moving from master to 9u7b45d272867b63d54f96d4aa57f8ecc479cd0
9u7b45 HEAD@{6}: checkout: moving from master to 9u7b45d272867b63d54f96d4aa57f8ecc479cd0
should give you a pretty rough idea of what you have done, that is, you have moved to a branchless commit in the past. There it is now, your precious little commit that was drifting in space without any label on it. Now go there and put a label on it, or that is to say, create a branch, whatever.cd ..
sudo rm -r ducking-git-repo-dir
git clone https://some.github.url/ducking-git-repo-dir.git
cd ducking-git-repo-dir