不求谌解

不求谌解

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

Weekly Sharing -- Rediscovering Git

image

It's my turn to do a technical share this week. After much thought, I decided to choose Git as the theme for this week's technical share. There are two reasons for this. First, I encountered some difficulties when using Git recently, which will be mentioned in detail later. Second, although I use Git every day, there are still some vague areas in terms of basic concepts, and I also want to further understand Git through this share.

Git Principles#

git

workspace: Workspace (current development location)

  • git pull: Fetches the latest code from the remote repository to the workspace => git fetch + git merge
  • git diff: Shows the modified but unstaged files

index: Staging area

  • git add: Submits the modified content in the workspace to the staging area

repository: Local repository

  • git commit: Submits the content in the staging area to the local repository
  • git fetch or git clone: Fetches/clones code from the remote repository to the local repository

remote repository: Remote repository

  • git push: Submits the content in the local repository to the remote repository

Common Questions#

  1. What does git push origin master do?

It pushes the content on the local master branch to the origin location and creates a master branch with the same name at the origin location.
Full command: git push origin master:master => git push <remote hostname> <local branch name>:<remote branch name>

  1. What is the difference between git merge and git rebase?

Example: Merge 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#

  1. The local project encountered an error and I 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.