This week it’s my turn to share some technical insights. After much consideration, I decided to choose Git as the theme for this week's technical sharing. There are two reasons: first, I've encountered some difficulties while using Git recently, which will be mentioned later. Second, even though I use Git every day, there are still some basic concepts that I find unclear, and I hope to further understand Git through this sharing.
Principles of Git#

workspace: Working directory (current development location)
git pull: Pull the latest code from the remote repository to the working directory =>git fetch+git mergegit diff: View modified but unstaged files
index: Staging area
git add: Submit changes from the working directory to the staging area
repository: Local repository
git commit: Submit the contents of the staging area to the local repositorygit fetchorgit clone: Pull/clone code from the remote repository to the local repository
remote repository: Remote repository
git push: Submit the contents of the local repository to the remote repository
Common Questions#
- What exactly does
git push origin masterdo?
It pushes the contents of the local master branch to origin, creating a branch named master at origin.
Full command: git push origin master:master => git push <remote hostname> <local branch name>:<remote branch name>
- The difference between
git mergeandgit rebase
Example: Merging the test branch into the master branch

Result of git merge

Result of git rebase

Recent Issues Encountered#
- Local project runs into errors, want to revert to a previous version => Revert the local repository to a previous version
git reset --hard/soft [commit point to revert to]
- Undo a commit that has already been pushed to the repository => Revert the remote repository to a previous version
git reset --hard [commit point to revert to]
git push origin HEAD --force