Git download, command line, and creation of remote warehouse

1. Download

Download mirror address

CNPM Binaries Mirror

Take my 2.42.0 version as an example,

Scroll down to the bottom of the latest version v2.42.0.windows.1/

Choose 64-bit Git-2.42.0-64-bi

After downloading, if there are no special requirements, just go to the next step without thinking. Be careful to select the download address.

Generally choose Git Bash to run

2. Git preparation

1. Because Git is a distributed version control system, all user names and email addresses are required as identifiers.

The git config --global parameter indicates that all Git repositories on this machine will use this configuration. Of course, different user names and emails can also be specified for a certain repository.

2. Go to the specified folder and cd E:/study/git. At this time, all commands will be executed in this folder.

3. Create folder mkdir testdemo

4. Enter the created file cd testdemo 

5. Turn the current directory into a git manageable library, so that there will be an extra .git file, which is hidden by default git init

3. Git command  

submit file demo

Now create a file test.txt under the testdemo file and add content as you like

1.git add test.txt adds the file to the temporary storage area

2.git commit -m "mainline submission file test.txt" 

Submit the file to the warehouse. Comments are enclosed in double quotation marks to make the query clearer.

3.git status Check if there are any uncommitted files

All have been submitted as follows

Now add content to the text and query again, it will show that the test.txt file has been modified.

4.git diff test.txt to see what has been modified

Then submit it again:

git add

git commit -m "New modifications to mainline test.txt"

version rollback

1. Now change the content of test.txt and submit it

2. View historical modifications git log

You can also only display the version number and remarks git log --pretty=oneline

3.Rewind

The first method: git reset --hard HEAD^ Roll back as many versions as you want^

The second method: git reset --hard HEAD~100 Go back to a few versions and write a few

The third method: roll back to the specified version number

Query version number git reflog

git reset --hard eb2c5ea back to the specified version

Undo changes

Method 1: Roll back the version

Method 2: Undo the order

For example, we add new content to test.txt

At this point we undo it git checkout -- test.txt   

Note: --There are spaces on both sides, otherwise an error will be reported

Canceled successfully

Delete files, recover deleted files

1. Now add a file a.txt to the directory, add it to the database and delete rm a.txt

2. Restore the file git checkout -- specify the file name

4. Establish a remote warehouse

1. Generate your own SSH KEY and fill in the configuration

Since the transmission between the local Git repository and the github repository is encrypted through SSH, a little setup is required:

查看C:\Users\Administrator下有没有.ssh文件,若没有,以管理员身份运行命令提示符

输入ssh-keygen -t rsa –C “[email protected]”

出现Enter file in which to save the key (C:\Users\Administrator/.ssh/id_rsa):

这里是指定路径和重命名,如果有多个git账户时需要设置

输入C:\Users\Administrator/.ssh/test_id_rsa

出现Enter passphrase (empty for no passphrase): 

这里是安全密码,可以直接回车不填

出现Enter same passphrase again:

直接回车

The following files will be generated under C:\Users\Administrator

id_rsa is the private key and id_rsa.pub is the public key

2. Log in to GitHub and add SSH Key

If you cannot log in to GitHub, you can go to the Microsoft Store to download Watt Toolkit and select GitHub Acceleration.

After successfully logging in, click the avatar in the upper right corner->select Settings->select SSH and GPG keys on the left->select New SSH key

You can see it after creating it

3. Associate the local warehouse with the github warehouse

git remote add origin ssh address, such as mine

Push the contents of the local warehouse master to test.git on GitHub: git push -u origin master

In this way, you can directly git push origin master and push the master's content to GitHub.

4. Remote library cloning

Create a new warehouse test2

git clone https://github.com/b-ronion/test2 to clone

5. Create and merge branches

1. Create a branch

git checkout -b dev creates and switches to this branch   
git branch View all branches and the current branch

git checkout master switch branches

2. Merge branches

git merge dev represents the master branch and merges the contents of the dev branch

3. Delete branch

git branch -d dev

Among the Git tutorials, the most detailed, simplest, simplest, and truly step-by-step tutorial - self-summary of learning on Zhihu (zhihu.com)

Guess you like

Origin blog.csdn.net/Ronion123/article/details/132602780