Git Shell Basic Command (official website dehydrated version)

Source: Internet
Author: User
Tags diff git shell

User Information

The first thing you should do when you install Git is to set up your user name and email address. This is important because each Git commit will use this information and it will be written to each of your commits and cannot be changed:

$ git config--global user.name "John Doe"
$ git config--global user.email [email protected]

Get command Help

$ git help verb
$ git verb help
$ Mans Git-verb

Check configuration information

If you want to check your configuration, you can use the GIT config--list command to list all the configurations that git can find at that time.

Initialize the warehouse in an existing directory

If you plan to use Git to manage existing projects, you only need to go to the project directory (local Path) and enter:
$ git init

If you are initializing a Git repository for versioning in a folder that already has files (rather than an empty folder), you should start tracking these files and submitting them. You can use the git add command to track a specified file and then execute a git commit commit:

$ **git Add * * *
$ git add LICENSE
$ git commit-m ' initial project version '

Download code

If you want to download the code that's hosted on Git, just know the code-managed path and enter:
$ git clone https://github.com/libgit2/libgit2
If you want to rename the download to a local directory then enter:
$ git clone https://github.com/libgit2/libgit2 foldername
This will perform the same action as the previous command, but the locally created warehouse name becomes foldername.

Log each update checks the current file status

To see which files are in what state, you can use the git status command. If you use this command immediately after cloning a warehouse, you will see output similar to this:

$ git status

Now, let's create a new README file under the project. If this file does not exist before, using the git status command, you will see a new non-tracked file:

$ echo ' Readme file content ' > Readme
$ git status

With this command you will see which files are not recorded by the repository.

Track new files

Put the readme you just created into the repository for tracking, just: $ git add readme
$ git status

Status overview

$ git status-s
M README
MM Rakefile
A lib/git.rb
M lib/simplegit.rb
?? LICENSE.txt
The newly added non-tracked files are preceded by the?? tag, the new file added to staging area has a tag in front of it, and the modified file has an M tag in front of it. You may notice that M has two possible positions, the M on the right indicates that the file has been modified but has not yet been put into the staging area, and the left side of M indicates that the file has been modified and put into the staging area. For example, the status report above shows that the README file has been modified in the workspace but has not yet put the modified file into staging area, the LIB/SIMPLEGIT.RB file has been modified and the modified file has been placed in the staging area. Rakefile has been modified in the workspace after it has been modified and submitted to staging area, so there are records in the staging area and workspace where the file has been changed.

Ignore file

In general, we always have some files that don't need to be managed by Git and don't want them to always appear in the list of non-tracked files. These are usually auto-generated files, such as log files, or temporary files created during compilation. In this case, we can create a file named. Gitignore, which lists the file modes to ignore. Take a look at a practical example:

$ cat. Gitignore
This command reads the contents of the. gitignore file and outputs it to the console

View staged and non-staged modifications

To see which parts of a file that have not yet been staged have been updated, enter git diff directly without parameters to see what is staged to be added to the next commit, you can use the git diff--cached command

Submit Updates

Before committing the update, GIT status looks at whether all the changes have been recorded, and then
$ git commit

May enter Vim mode, this time CTRL + C input: Wq Save the file and exit, you can also

$ git commit-m "story 182:fix benchmarks for Speed"

Skip using Staging Area

The normal submission process is:
* git Status View status
* git Add. Put into staging area
* git commit-m "commit record"

To submit, if you find this too troublesome, can-a to skip the staging area: $ git commit-a-M ' added new benchmarks '

Remove files from

Remove the file in two categories, whether to keep the file in the current directory, you need to keep:
$ git rm--cached filename does not need to be preserved:
$ git rm filename

View commit History

$ git log
Can. For more high-end usage, view documents

Undo Action

A revert operation similar to SVN:
$ git checkout--filename.md
$ git status

Use of remote warehouses
    • New code Publish to the new warehouse if you want to publish your git-managed code to GitHub, follow these steps:
      echo "README file contents" >> readme.md
      Git init
      git add readme.md
      Git commit-m "First commit"
      Git remote add Origin https://github.com/cuicheng11165/1758.git
      git push-u Origin master

    • Existing warehouses are published to the remote repository if Git is already hosted locally, you only need to:
      Git remote add Origin https://github.com/cuicheng11165/1758.git
      git push-u Origin master

Pull remote changes are divided into pulls and fetch,pull equivalent to Fetch+merge
* Use of Fetch:
Git fetch Origin Master
git merge
* Use of Pull:
git pull Origin master

Official documents

The blog's documentation is hosted on: http://simmon.club/blog/git-cmd-instruction/

 

Git Shell Basic Command (official website dehydrated version)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.