One of git: Install git under windows and use this summary

1: Download git windows version, open git bash after installation

 

2: Set account email information

 

3: Create a repository folder

In this way, the C:/git/ repository is built, and a .git directory will be automatically generated in the git directory. This directory is used by Git to track and manage the repository. Of course, this is a hidden directory under linux.

You don't have to create a Git repository in an empty directory, you can choose a directory that already has something.

Notice:

It is not recommended to use git to manage documents written in word and notepad under windows, because word is a binary file and git can't do anything, and some characters will be automatically added before the second notepad encoding, so it is recommended to write in notepad++ under win, and use utf -8 no bom format.

 

4: Add files to the repository

  • The first step, use the command git add <file>, note that it can be used repeatedly to add multiple files;

  • The second step, using the command git commit -m "说明", is done.

Create a mysql multi-instance configuration file in the git directory. mysql3307.cnf

git add filename adds the file to the repository

$ git add mysql3307.cnf

This warning says that the CRLF newline has been replaced with LF, LF is the newline under linux, and CRLF is the newline of win.

 

Submit the file to the repository

git commit -m "Description of this commit"

 

5: Modify the file

Create a new readme.txt file, add git, and then modify readme.txt to add a line of content

$ echo version2 add a new line >readme.txt

git status Check the warehouse status, you can see that the readme.txt status has been modified, but there are no modifications that are ready to be submitted.

 

git diff Now let's check what content has been modified in readme.txt, so that it is more reassuring to submit. Submitting changes and submitting new files are the same two steps, git add, git commit

$ git add readme.txt

$ git commit -m "v2 add a new line"
[master 6257734] v2 add a new line
1 file changed, 1 insertion(+), 1 deletion(-)

summary

  • To keep track of the status of the workspace, git statuscommands are often used.

  • If it git statustells you that a file has been modified, git diffyou can view the modified content. Confirm that there is no problem and then add >commit

6: Version returned

First, git log can view all modification records. To view the logging of the specified file can git log readme.txt

The --pretty=oneline parameter can concisely display the commit and description. Note that the --pretty=oneline parameter should be written before the specific file. HEAD represents the current version. You can see that the current version is add a path.

In Git, use HEADindicates the current version, the previous version is HEAD^, the previous version is , of course , it is easier to HEAD^^write 100 versions up to 100 , so it is written .^HEAD~100

 

The git reset command is used to change the version, you can see that HEAD has been rolled back to the previous version.

cat it, and sure enough, it has been rolled back to version 2

 

If you find that you have made a mistake and want to go back to the latest version, what should you do to cancel this rollback? You can use git reset --hard "commit id", so you can go to the version with the specified commit id.

The version number does not need to be written in full, the first few digits are enough, Git will automatically find it, as long as the id is unique.

 

 

git reflog

If you can't find the commit id of the deleted version, you can use git reflog to display the commit records of all versions. git log cannot view deleted commits, but git reflog can.

 

If a remote library exists:

Use the git revert <commit_id> operation to realize the advance. git revert is different from git reset. It does not erase the commit_id after the "reversion", but normally treats it as a "commit" to generate a new operation record, so You can push, but will not let you pull again.

 

7: Delete files

Create a new test.txt file and submit it to the repository.

rm test.txt delete file

 

If you delete it wrongly and need to restore it, git checkout -- test.txt git checkoutactually replaces the version in the workspace with the version in the repository, no matter if the workspace is modified or deleted.

 

如果确定要从版本库也删除test.txt,  git rm test.txt,andgit commit 提交到版本库

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324520528&siteId=291194637