If you want to get in touch with anything quickly, you must practice it first.
Come on! Lange, you can do it!
Git official website: https://git-scm.com/downloads When
installing, the default options are fine.
After the installation is complete, you need the last step to set up, type in the command line:
(Set in the downloaded Git Bush)
$ git config --global user.name "Your Name"
$ git config --global user.email "[email protected]"
*Note the -global parameter of the git config command. Using this parameter means that all Git repositories on your machine will use this configuration. Of course, you can also specify a different user name and email address for a certain repository.
Start operation
----The following operations are all done in Git Bush.
Create a repository
$ mkdir learngit
$ cd learngit
$ pwd #pwd命令用于显示当前目录
The second step is to turn this directory into a warehouse that can be managed by Git through the git init command:
$ git initInitialized empty Git repository in /Users/michael/learngit/.git/
About git adding files to the Git repository
$ pwd
$ vi readme.txt
$ git add readme.txt
Go back to the readme.txt file and modify the content:
$ pwd
/c/Users/lange/learngit
$ vi readme.txt
Using $ git status to view the
git status command can let us know the current status of the warehouse at all times. The above command output tells us that readme.txt has been modified, but there is no modification ready to submit.
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: readme.txt
no changes added to commit (use "git add" and/or "git commit -a")
To view the modification details:
$ git diff readme.txt
Committing modification and submitting a new file are the same two steps,
$ git add readme.txt
Before performing the second step of git commit, we will run git status to see the status of the current warehouse:
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: readme.txt
git status tells us that the changes to be submitted include readme.txt, and in the next step, you can safely submit:
$ git commit -m "add distributed"
[master e475afc] add distributed
1 file changed, 1 insertion(+), 1 deletion(-)
After submission, we will use the git status command to see the current status of the warehouse:
$ git status
On branch master
nothing to commit, working tree clean
Git tells us that there are currently no changes that need to be committed, and that the working directory is clean (working tree clean).
The git log command displays the commit log from the most recent to the farthest.
Another modification record is added:
then save it and use $git log to view the three versions.
If you think the output information is too much and you are dazzled, you can try adding – pretty=oneline parameters:
First of all, Git must know which version the current version is. In Git, the current version is represented by HEAD, which is the latest commit 1094adb... (note that my commit ID is definitely different from yours). The previous version is HEAD , go up One version is HEAD . Of course , it is easier to count the 100 versions up to 100 , so it is written as HEAD~100.
If we want to revert the current version of append GPL to the previous version add wrote a readme file, we can use the git reset command:
see if the content of readme.txt is the version add wrote a readme file
If we want to go back to the third version, What should I do?
If you haven't closed it, you can find the first few letters or numbers of the file just now
and use git reset --hard ***** to go back and forth.
When you use $ git reset --hard HEAD^ to revert to the add wrote a readme file version, and then want to revert to append GPL, you must find the commit id of append GPL. Git provides a command git reflog to record every command you make:
Undo: The
command git checkout-readme.txt means to undo all the modification of the readme.txt file in the work area. There are two situations:
one is that the readme.txt has not been put into the temporary storage area since the modification, now , Undo the modification and return to the same state as the version library;
one is that readme.txt has been added to the temporary storage area and then modified. Now, the undo modification returns to the state after adding it to the temporary storage area.
In short, it is to make this file back to the state of the last git commit or git add.
Git also tells us that using the command git reset HEAD can undo the changes in the staging area (unstage) and put it back into the work area:
and then execute git checkout – readme.txt
Delete the file: rm test.txt
First, if you really want to delete the file from the repository, use the command git rm to delete it, and git commit: The
other case is the deletion of the file , because there are still in the repository, so You can easily restore the deleted files to the latest version:
$ git checkout – test.txt
*Note: Files that are deleted before being added to the repository cannot be recovered!