Date

Changing Git history

Check Changes from Last Commit

git diff
git add -p
git rm
git mv
git checkout [-p] <file>
git restore <file>
git reset [-p]
git restore --staged <file>
git stash
git stash apply
git checkout -b new_branch HEAD~2
git reset --hard HEAD~3  # Go back in time, throwing away changes
git reset --soft HEAD~3  # Set HEAD to point to an earlier commit
git reset --hard  # Wipe out differences in the working tree

git stash
git checkout -b new-branch HEAD~3   # head back in time!

git stash  # because it's always a good thing to do
git reset --hard HEAD~3  # go back in time
git reset --hard HEAD@{1}  # oops, that was a mistake, undo it!
git stash apply  # and bring back my working tree changes
git commit --amend
git revert <commit tag>

Best Practices for Collaboration

  1. Always synchronize your branches before starting any work on your own.
  2. Make changes that are self-contained.
  3. Avoid having very large changes that modify a lot of different things. (Try to make changes as small as possible as long as they're self-contained.)
  4. When working on a big change, it makes sense to have a separate feature branch.
  5. Regularly merge changes made on the master branch back onto the feature branch.
  6. Have the latest version of the project in the master branch, and the stable version of the project on a separate branch.
  7. You shouldn't rebase changes that have been pushed to remote repos.
  8. Write commit messages.
  9. Only edit the same branch when necessary after submitting a pull request.
git remote -v
git rebase [-i]
git push [-f] [-u] origin branch_name

codeowner: https://docs.github.com/en/free-pro-team@latest/github/creating-cloning-and-archiving-repositories/about-code-owners

code improvement: clear/meaningful variable names GitHub

Configuration

git config [--global]