This article is excerpted from Liao Xuefeng’s Git tutorial, which is already very detailed. I just copied some notes for my own understanding. You do not understand is normal………….
Common commands and their meanings:
View the commit journal Git log
Git log –pretty=oneline git log –pretty=oneline
As a reminder, you see a bunch of things like 3628164… 882e1e0 has a commit id (version number). Unlike SVN, Git has a commit id that is not 1,2,3… Instead, it’s a very large number calculated by SHA1 in hexadecimal notation, and the COMMIT ID you see is definitely different from mine, whichever is yours. Why is the COMMIT ID represented by such a large string of numbers? Because Git is a distributed version control system, we will have to study how many people work in the same version library. If everyone uses 1,2,3… As a version number, that’s definitely a conflict.
The version rollback git reset
First, Git must know what the current version is. In Git, the **HEAD represents the current version, which is the latest commit 3628164… 882e1e0 (note that my submission ID is not the same as your submission ID), the previous version is HEAD^**, the previous version is **HEAD^^** *, of course, 100 ^ is easy to count up to 100 ^, so **HEAD~100**.
Use git reset: $git reset –hard HEAD^
If you want to go back to the latest version, you can do so, provided that you have not closed it. Find the file you need to commit with id 3628164… Git reset –hard 3628164 — git reset –hard 3628164 — Git reset –hard 3628164 Of course, you can’t just write the first one or two, because Git may find multiple version numbers and never know which one it is.
Now, what if you fall back to a version, turn it off, regret it the next morning, and want to go back to the new version? What if the new version of the COMMIT ID cannot be found?
In Git, there is always a remedy for regret. If you want to restore to the Append GPL with $git reset –hard HEAD^, you must find the COMMIT ID of the Append GPL. Git reflog Git reflog Git reflog
git reflog
Summary:
- The version that HEAD points to is the current version, so Git allows us to travel through the history of versions using the command Git reset –hard commit_id.
- Before shuttling, use **
git log
** You can view the commit history to determine which version you want to fall back to. - To return to the future, use violence
git reflog
** View the command history to determine which version to go back to in the future.
Working Directory
A directory that you can see on your computer, like my Learngit folder, is a workspace:
Repository Repository
A workspace has a hidden directory. Git, which is not a workspace, but a git repository.
Git’s repository contains a number of things, the most important of which is a staging area called stage (or index), the first branch that Git automatically creates for us, master, and a pointer to master called HEAD.
Adding files to Git repository is done in two steps:
The first step is to add the file with git add, which essentially adds the file changes to the staging area.
The second step is to commit the changes with git commit, which essentially commits the entire contents of the staging area to the current branch.
Because Git automatically created the only master branch for us when we created the Git repository, Git commit is now committing changes to the master branch.
You can simply say that all changes to the file that need to be committed are put into the staging area, and then commit all changes to the staging area at once.
Adding files to Git repository is done in two steps:
The first step is to add the file with git add, which essentially adds the file changes to the staging area.
The second step is to commit the changes with git commit, which essentially commits the entire contents of the staging area to the current branch.
Because Git automatically created the only master branch for us when we created the Git repository, Git commit is now committing changes to the master branch.
You can simply say that all changes to the file that need to be committed are put into the staging area, and then commit all changes to the staging area at once.
Once committed, the workspace is “clean” if you haven’t made any changes to it:
$ git status
# On branch master
nothing to commit (working directory clean)
Copy the code
Now the repository looks like this, and the staging area is empty:
So the git add command essentially puts all the changes to the Stage, and then commits them all to the branch at once with a Git commit.
Cat file names can be used to view the contents of files
First change -> git add -> Second change -> git add -> git commit
Ok, now, commit the second change and start the summary.