不求谌解

不求谌解

💻 Web Dev / Creative 💗 ⚽ 🎧 🏓
twitter
github
jike
email

Weekly Share -- Rediscovering Git

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#

git

workspace: Working directory (current development location)

  • git pull: Pull the latest code from the remote repository to the working directory => git fetch + git merge
  • git 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 repository
  • git fetch or git 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#

  1. What exactly does git push origin master do?

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>

  1. The difference between git merge and git rebase

Example: Merging the test branch into the master branch

git-test

Result of git merge

git-merge

Result of git rebase

git-rebase

Online Demo

Recent Issues Encountered#

  1. 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]
  1. 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 

More#

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.