Git distributed management tool

Install on Windows

Install Git on Windows as follows:

  • Install using the official version

The official version can be downloaded from the official Git website. Open git-scm.com/download/wi…

Note that this is a project called Git for Windows (also known as msysGit), and Git is a separate project; For more information, visit msysgit.github. IO /.

  • Taobao mirror address Download speed npm.taobao.org/mirrors/git…

After the download is complete, install it as prompted. The first thing you need to do after installing Git is set up your username and email address. This is important because every Git commit uses this information, which is written to your commit and cannot be changed:

After the installation is complete, you will have these more:

Git bash is a command window

You right-click in that directory and you go into that directory and you use Linux commands in that directory

Common Linux commands

Always use these basic commands!

1), CD: change directory.

2), CD.. back to the previous directory, directly CD to the default directory

3), PWD: display the current directory path.

4), ls(ll): both list all files in the current directory, but ll(two LL) list more detailed contents.

5), touch: create a new file such as touch index. Js will create a new file in the current directory.

6) rm: Delete a file and rm index.js will delete the file.

7), mkdir: create a directory, is to create a folder.

8), rm -r: delete a folder, rm -r SRC delete directory SRC

Rm -rf/Don't try this on Linux! Delete all files from your computer!Copy the code

HTML SRC index.html is the file we want to move. SRC is the directory we want to move.

Reinitialize the terminal/clear the screen.

11), clear the screen.

12), history View command history.

13) I can help you.

14), exit.

15), #

  • Git configuration All configuration is actually saved locally

Global configuration file location Location of the current user profile If you want to check your configuration, usegit config --listCommand to list all the configurations Git can find at the time.

You may see duplicate variable names because Git reads the same configuration from different files (for example:/etc/gitconfig~/.gitconfig). In this case, Git uses the last configuration of every variable it finds.

You can type it inGit config < key > :To check a Git configuration, for example:

$git config user. Name by cui CuiCopy the code

Setting the configuration file

$git config --global user.email [email protected]Copy the code


Git repository

Local warehouse setup

  • Create a directory
$ mkdir learning-git
$ cd learning-git
$ pwd
/Users/xxm/learning-git
Copy the code
  • Initialize the warehouse
$ git init
Initialized empty Git repository in /Users/xxm/learning-git/.git/
Copy the code

Git repository is an empty Git repository, with an extra Git directory in your current directory. If you do not see the.git directory, you will be able to create a Git repository. That’s because the directory is hidden by default and can be seen with the ls-ah command.

Clone an existing warehouse

When you run git clone, every version of every file in your remote Git repository is pulled down by default.

Git clone

For example, to clone Git’s link library libgit2, use the following command:

File name is help - docs $$git clone git clone https://codechina.csdn.net/codechina/help-docs build an alias https://codechina.csdn.net/codechina/help-docs mydocsCopy the code

  • Create the read.txt file to add to the repository using the get Add filename

Step two, use commandsgit commitTell Git to commit the file to the repository: here’s a quick explanationgit commitCommand,-mYou can enter anything you want, preferably something meaningful, so you can easily find the changes in your history. git commitAfter the command is successfully executed, the following information is displayed:

  1. File changed: 1 file changed (our newly added readme.txt file)
  2. Insertions: Insert two lines (readme.txt has two lines)

Git files need to be added and commit. Since you can commit many files at once, you can add different files multiple times, such as:

$ git add file1.txt
$ git add file2.txt file3.txt
$ git commit -m "add 3 files."
Copy the code
  • Git status

git statusCommands allow us to keep track of the current state of the warehouse, and the command output above tells us,read.txtChanges that have been modified but are not ready for submission.

  • Get diff File name View modification records

  • Git log Displays commit records

  • Git reset returns the previous version

First, Git must know which version is currently available. In Git, useHEADRepresents the current version, which is the latest commite55063aThe last version wasHEAD^The previous version wasHEAD^^And, of course, go up 100 versions and write 100^It’s a little bit harder to count, so let’s write itHEAD~100File contents go back to the previous version

  • Git reflog View operation records

  • Git reset –hard “Version name” to switch to the latest version

File back to original

  • summary

  • Scenario 1: When you tamper with the contents of a file in your workspace and want to discard the workspace changes directly, use git checkout — file

  • Git reset HEAD

    if you want to discard a file that you have changed in your workspace and added to the staging area, go back to scenario 1 and follow scenario 1 in step 2

  • Scenario 3: If inappropriate changes have been committed to the repository, you can undo the commit with git reset –hard commit_id, but only if they have not been pushed to the remote repository

Git Branch Management

Create a branch

$ git checkout -b dev
Switched to a new branch 'dev'
Copy the code

Git checkout the git checkout command with the -b parameter creates and switches.

$ git branch dev
$ git checkout dev
Switched to branch 'dev'
Copy the code

Use git branch to view the current branch:

$ git branch
* dev
  master
Copy the code

The git branch command lists all branches, with the current branch preceded by an asterisk

  • git checkout masterSwitch the branch to master
  • git merge devMerge branch dev
  • git branch -d devDelete the branch

We’re just left with the master branch

To create and switch to a new dev branch, use:

$ git switch -c dev
Copy the code

To switch directly to the existing master branch, you can use:

$ git switch master
Copy the code

Using the new Git switch command is much easier to understand than git checkout.

Git usually merges branches in Fast Forward mode if possible, but in this mode, branch information is discarded when the branch is deleted.

If you force the Fast Forward mode to be disabled, Git generates a new COMMIT at merge so that the branch history shows the branch information.

Git merge git merge git merge

Git merge –no-ff -m “merge with no-ff” dev –no-ff

Git log –graph –pretty=oneline –abbrev-commit

  • Git branch
Git branch [branch-name] # create a new branch $git branch -d [branch-name] $git branch -d [branch-name  origin --delete [branch-name]$ git branch -dr [remote/branch]Copy the code

Create remote warehouse and integrate IDEA on GITee (fast national code cloud)

Open the git command window and enter ssh-keygen. SSH folder will be generated in the user directory

Then register Gitee and open SSH for Settings

Open the id_rsa.pub file just under.ssh, copy its contents and paste it into the gitee SSH Settings key text box with a random title and save

Create a remote repositoryReplication remote address pull item

Copy the pulled file to your own project to open the projectI found that idea project has many of these

Add commit remote commit using git command on command lineAdded to remote repository successfully

Recommend crazy god said git tutorial feel speak very good address