Git 筆記

Git notes

R4 Cheng
2 min readJul 16, 2021
Photo by Yancy Min on Unsplash

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
https://dev.to/lydiahallie/cs-visualized-useful-git-commands-37p1

No-fast-forward (--no-ff)

  • Git creates a new merging commit on the active branch
https://dev.to/lydiahallie/cs-visualized-useful-git-commands-37p1

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
https://dev.to/lydiahallie/cs-visualized-useful-git-commands-37p1

Actions

  • reword: Change the commit message
  • edit: Amend this commit
  • squash: Meld commit into the previous commit
  • fixup: Meld commit into the previous commit, without keeping the commit's log message
  • exec: Run a command on each commit we want to rebase
  • drop: 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}!

https://dev.to/lydiahallie/cs-visualized-useful-git-commands-37p1

References

  1. https://youtu.be/lX9hsdsAeTk (未讀)
  2. Lydia Hallie; CS Visualized: Useful Git Commands (2020.4)
  3. Fireship; 13 Advanced (but useful) Git Techniques and Shortcuts (2021.9)

--

--

R4 Cheng
R4 Cheng

Written by R4 Cheng

「0」が過去で「1」が未来「今」は何処にもない

No responses yet