Git

Git

Git,Code repository management system,Distributed version control software

Visit Site →

Official Git website, code repository management system, distributed version control software

What is Git?

Git is a distributed version control software, originally created by Linus Torvalds and released in 2005 under the GPL license agreement. It was initially designed to better manage the development of the Linux kernel. It should be noted that this is different from the GNU Interactive Tools. The initial driving force behind Git's development came from BitKeeper and Monotone.

Git Official Website:https://git-scm.com/

Git is a free, open-source distributed version control system that can quickly and efficiently handle a variety of projects, from small to large.
Git's feature is branching, and that's how they dare to draw their icons.
By the way, I should mention that Git and Linux are from the same family, so the native commands that can run on the Linux system can also run on Git, and vice versa.

Detailed Introduction to Git

Git is a distributed version control software released by Linus Torvalds in 2005. It helps developers track the change history of projects and allows multiple people to collaborate on the same codebase. In Git, each person has their own local copy, which can easily synchronize changes to the main repository. The advantage of this distributed system is that it can avoid single points of failure, allowing developers to continue working even if the main repository is unavailable, which is not possible in centralized version control systems.

In addition to the advantages of the distributed system, Git also provides many other features, including branching and merging. Branching allows developers to develop new features or solve problems without affecting the main codebase. Merging allows developers to combine different code branches into a single entity, which is a necessary step to ensure that all changes are correctly merged into the main codebase.

In addition, Git also provides other features, such as archiving, hooks, and conflict resolution. Archiving allows developers to create specific version archive files to share them with others or back them up. Hooks are a mechanism that can run custom scripts at specific events. Conflict resolution is a method to resolve the situation where multiple people change the same file simultaneously, ensuring that all changes are correctly merged.

🛠️ Git Installation

Before using Git, we need to install Git first. Git currently supports running on Linux/Unix, Solaris, Mac, and Windows platforms.

Download addresses for Git installation packages for various platforms: http://git-scm.com/downloads

This article describes the installation of Git on the Windows system, installation address: https://npm.taobao.org/mirrors/git-for-windows/, the installation process is not verbose, just keep clicking "Next" after downloading. For specific download and installation tutorials, please refer to Git Installation and Configuration – (link address: https://www.runoob.com/git/git-install-setup.html)

🚀 1. Comprehensive Git Commands (organized into a table for easy reference)

Repository Creation Commands

Commands Description
git init Initialize a repository, create a new Git codebase in the current directory, which is essentially creating a .git directory withobjects,refs/head,refs/tagsand template files..gitdirectory.
git clone[url] Copy aremote repository, which is to download a project and its entire code history.

Configuration

Commands Description
git config --list Display the currentGit configuration
git config -e [–global] Edit the Git configuration file.
git config [–global] user.name “[name]”
git config [–global] user.email “[email address]”
Set user information for code submission

Add / Delete Files

Commands Description
git add [file1] [file2] ... Addspecified filesto the staging area
git add [dir] Addspecified directoryto the staging area, including subdirectories
git add . Add all files in the current directoryto the staging areagit add -p
Add each change before confirming For multiple changes to the same file, it can implement
partial commitsgit rm [file1] [file2] …
Delete workspace files and put this deletion into the staging areagit rm –cached [file]
Stop tracking the specified file, but the file will remain in the workspace git mv [file-original] [file-renamed]
Rename file and put this rename into the staging areaCode Commit

Commands

Description git commit -m [message]
Commit the staging area to the repository area git commit [file1] [file2] … -m [message]
Commit the specified files in the staging area to the repository areagit commit -aCommit all changes in the workspace since the last commit directly to the repository area
git commit -v Commit and displayall diff informationgit commit –amend -m [message]
Use a new commit to replace the last commit If there are no new changes in the code, it is used to rewrite the commit information of the last commitgit commit –amend [file1] [file2] …
Redo the last commit and include the new changes of the specified files
Branching
Commands Descriptiongit branch

List all

local branches git branch -r
List all remote branchesgit branch -a
List all local branches and remote branchesgit branch [branch-name]
Create a new branch but stay on the current branch git checkout -b [branch]Create a new branch and switch to it
git branch [branch] [commit] Create a new branch pointing to a specified commit
git branch –track [branch] [remote-branch] Create a new branch and establish a tracking relationship with the specified remote branch
git checkout [branch-name] Switch to the specified branch and update the workspace
git checkout – Switch
to the previous branch git branch –set-upstream [branch] [remote-branch]
Establish a tracking relationship between the existing branch and the specified remote branch git merge [branch]Merge
the specified branch into the current branch git cherry-pick [commit]
Select a commit and merge it into the current branch git branch -d [branch-name]Delete branch
git push origin –delete [branch-name] or
git branch -dr [remote/branch] Delete remote branch
Tags
Commands
Description
git tag

List all tags

git tag [tag] Create a new tag in the current commit
git tag [tag] [commit] Create a new tag in a specified commit
git tag -d [tag] Delete
local tag git push origin :refs/tags/[tagName]
Delete remote taggit show [tag]
View tag information git push [remote] [tag]Submit
specified tag git push [remote] –tags
Submit all tagsgit checkout -b [branch] [tag]
Create a new branch pointing to a specific tag View information and historyCommands
Description git status

Display files with changes

git log Display the version history of the current branch
git log –stat Display commit history and the files changed by each commit
git log -S [keyword] Search commit history based on keyword
git log [tag] HEAD –pretty=format:%s Display all changes after a specific commit, with each commit occupying a line
git log [tag] HEAD –grep feature Display all changes after a specific commit, where the "commit message" must meet the search criteria
git log –follow [file] or
git whatchanged [file] Display the version history of a specific file, including file renaming
git log -p [file]
Display each diff related to a specific file
git log -5 –pretty –oneline
Display the past 5 commits
git shortlog -sn Display all users who have submitted, sorted by submission count
git blame [file] Display who has modified a specified file and when
git diff Display
the differences between the staging area and the workspace git diff –cached [file]
Display the differences between the staging area and the previous commitgit diff HEADDisplay
the differences between the workspace and the latest commit in the current branch git diff [first-branch]…[second-branch]Displaythe differences between two commits
git diff –shortstat “@{0 day ago}” Display how many lines of code you have written todaygit show [commit]Display metadata and content changes of a specific commit
git show –name-only [commit] Display files changed by a specific commitgit show [commit]:[filename]Display the content of a specific file at the time of a specific commit
git reflog Display the recent commits on the current branch
Show commit details Display metadata and content changes of a specific commit
git show –name-only [commit] Display files changed in a specific commit
Show content of a specific file in a commit Display content of a file at the time of a specific commit
git reflog Show recent commits in the current branch