Git 筆記
git checkout
// Go to previous branch
git checkout -
git switch
Instead of git checkout
to switch branch
git merge
Fast-forward (--ff
)
- This type of merge doesn’t create a new commit

No-fast-forward (--no-ff
)
- Git creates a new merging commit on the active branch

git rebase
- A
git rebase
copies the commits from the current branch, and puts these copied commits on top of the specified branch - A
git rebase
changes the history of the project as new hashes are created for the copied commits! - Rebasing is great whenever you’re working on a feature branch, and the master branch has been updated. You can get all the updates on your branch, which would prevent future merging conflicts

Actions
reword
: Change the commit messageedit
: Amend this commitsquash
: Meld commit into the previous commitfixup
: Meld commit into the previous commit, without keeping the commit's log messageexec
: Run a command on each commit we want to rebasedrop
: Remove the commit
git reflog
Say that we actually didn’t want to merge the origin branch. When we execute the git reflog
command, we see that the state of the repo before the merge is at HEAD@{1}
. Let's perform a git reset
to point HEAD back to where it was on HEAD@{1}
!
