Summary of common Git commands and summary of common git commands

Source: Internet
Author: User
Tags how to use git git commands git cheat sheet ruby on rails

Summary of common Git commands and summary of common git commands

1. About deletion and rollback


1 git rm -- cached file wants git to stop tracking this file, but does not want to delete it from the hard disk.


2. When deleting files in the directory managed by git, you can select either of the following methods:
① Rm + git commit-am "abc"
② Git rm + git commit-m "abc"

3 if rm is used, but you want to restore git checkout -- file


4 gir rm:

① If git reset HEAD is not submitted

② You have already commit git reset -- hard <previous version, which can be viewed by git reflog>


5. Restore after modification

① When you change the content of a file in the workspace and want to discard the modification, run git checkout -- file.

② When you not only disrupt the content of a file in the workspace, but also add the file to the temporary storage area, you want to discard the modification, in two steps, the first step is to use the command git reset HEAD file, return to scenario 1. Step 2: perform operations based on scenario 1.

③ If an inappropriate modification has been submitted to the version library and you want to cancel this submission, perform version rollback (git reset -- hard)

Indicates the latest version. The previous version is HEAD ^, the previous version is HEAD ^, And the last version is HEAD ^. The first version is written as HEAD ~ 100.


2. view history and modifications


1 git log

2 git log -- pretty = oneline

3 git diff HEAD -- file: view the difference between the latest version in the workspace and the version Library

4 git log -- graph -- pretty = oneline -- abbrev-commit is better at viewing Branch records



3. Git Configuration


1. Initial Configuration

Git config -- global user. name "Your Name"

Git config-global user. email "email@example.com"


2. Add remote repository and push

Git remote add origin git@github.com: lanbing510/learngit. gitre

Push git push-u original master for the first time after Configuration

Adding-u git not only pushes the content of the local master Branch to a remote new master branch, but also associates the local master branch with the remote master branch, in the future, you can simplify the command: git push original master


3. clone the git clone remote repository address


4. Ignore configuration files

① Create a special. gitignore file under the root directory of the Git workspace, and then fill in the file name to be ignored, Git will automatically ignore these files, some configuration files can see the https://github.com/github/gitignore

② Alternatively, run the git config -- global core. excludesfile ~ command ~ /. Gitignore_global add to git global configuration to reduce repeated rule definitions for each layer directory. For more information, see http://blog.csdn.net/lanbing510/article/details/40588323


5. Configure aliases

For example, after git config -- global alias. unstage 'reset head', you can use git unstage to undo the modification of the temporary storage area (unstage) and put it back to the workspace.

Git config -- global alias. last 'Log-1' --> displays the last modified git last

Git config -- global alias. lg "log -- color -- graph -- pretty = format: '% Cred % h % Creset-% C (yellow) % d % Creset % s % Cgreen (% cr) % C (bold blue) <% an> % Creset '-- abbrev-commit "git lg better display log

The Git configuration files of Each repository are stored in the. git/config file.



Four Branches


1. Create and switch branches

Git checkout-B newbranch

The above command is equivalent to git branch newbranch and git checkout newbranch


2. Run the git branch command to view the current branch.


3. merge a branch to the current branch: git merge name

4. Delete branch: git branch-d name


5 disable fast forward: Add-no-ff to merge

If possible, Git uses the "Fast forward" mode when merging branches, but in this mode, branch information is lost after the branches are deleted. If you want to forcibly disable the "Fast forward" mode, Git will generate a new commit at merge, so that the branch information can be seen from the branch history.


6. When the task is not completed, you must fix the previous bug.

Git stash stores on-site work

Git checkout master

Git checkout-B fixbug

Git add

Git commit-m "fix bug"

Git checkout master

Git merge -- no-off-m "merge bug fix fixbug" fixbug

Git branch-d fixbug

Git stash list to list stash content

Git stash apply for Recovery + git stash drop Delete stash = git stash pop


7. Develop a new feature. It is best to create a new branch.

Git branch-D <name> drop a branch that has not been merged


8. Push Branch

Git push origin master push master Branch

Git push origin dev push new branch

Master is the master branch and must be synchronized remotely at any time.

Dev is a development branch. Team members need to work on it and need to be remotely synchronized.

The bug branch is used to fix bugs locally and does not need to be pushed to a remote server unless the boss needs

Whether the feature is pushed depends on whether you work with others for development.


9 git clone

After cloning from another computer, you can only see the master branch, but not the dev. To develop on dev, you must create the dev branch of the remote origin to the local: git checkout-B dev origin/dev


10 git push failed

The reason is that you have updated your local data remotely. First, git pull merge

If a conflict exists in the merge, resolve the issue. If git pull prompts no tracking information, the link between the local branch and the remote branch is not created: git branch -- set-upstream branch-name/origin/branch-name



Five tags


1 git tag name

Example: git tag v0.1 6224937

2. view the git tag

3 git show <tag> View tag Information

4. You can also create a label with instructions. Use-a to specify the label name and-m to specify the description text: git tag-a v0.1-m "version 0.1 released" 3628164

5 use the PGP signature label: git tag-s <tagname>-m "blablabla..." you must first install gpg

6. push a local Tag: git push origin <tagname>

7. push all unpushed local tags: git push origin -- tags

8. delete a local tag: git tag-d <tagname>

9 delete a remote Tag: git push origin: refs/tags/<tagname>



Build a Git Server


Reference http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/00137583770360579bc4b458f044ce7afed3df579123eca000




Seven Common Problems


1! [Rejected] master-> master (non-fast-forward)

Solution:

① Git push-f for forced pushing

② Git fetch git merge


Summary: Git Cheat Sheet







What are common git commands?

Git clone
Git push
Git pull
The three have the highest usage.

How to Use git mv command

Git command (gnu interactive tools)
Function Description: file administrator in text mode.
Syntax: git command
Note: The git command is used to manage files. It is similar to Norton Commander in DOS and has an interactive operation interface. Its operation method is almost the same as that of Norton Commander:
F1: Execute the info command to query the command information. You are required to enter the name you want to query.
F2: Execute the cat command to list the file content.
F3: Execute the gitview command to view the file content.
F4: Execute the vi command to edit the file content.
F5: run the cp command to copy a file or directory. You are required to enter the target file or directory.
F6: Execute the mv command, move the file or directory, or change its name. You are required to enter the target file or directory.
F7: run the mkdir command to create a directory.
F8: Execute the rm command to delete files or directories.
F9: Execute make commands. When executing commands or compiling programs in batches, you are required to enter relevant commands.
F10: Leave the git file administrator.

----------------- Use the Git command -------------------------------
Git is a distributed version control tool. This article begins with introducing Git and focuses on the basic commands and usage skills of Git, so that you can try to use Git at the same time, experience the impact of a version control tool on development is as follows:
The first part introduces some common Git commands, which are interspersed with the basic concepts and principles of Git.
The second part focuses on how to use Git. At last, you will create an open-source project on Git Hub to start your Git practical journey.

What is Git?
Git defines Wikipedia: it is a free, distributed version control tool, or a source code management tool that emphasizes high speed.
Git was initially developed by Linus Torvalds for Linux kernel management. Each Git working directory is a completely independent code library with complete history and version tracking capabilities, independent of the network and central server.
The emergence of Git has reduced the pressure on many developers and open-source projects to manage branch code. Due to its good control of branches, developers are encouraged to contribute to projects they are interested in. In fact, many open-source projects, including Linux kernel, Samba, X.org Server, and Ruby on Rails, have transitioned to using Git as their own version control tools. For developers who like to write code, there are two major advantages: We can submit our own code and view the code version anywhere (on the subway station at work; we can open many branches to practice our ideas, and the overhead of merging these branches is almost negligible.

Git 1 + 1
Now I will go to the real topic of this article and introduce the basic commands and operations of Git, starting with the initialization, basic operations, and unique common commands of Git version libraries, let everyone start using Git.
Git usually has two methods for initialization:
Git clone: this is a simple initialization method. when you already have a remote Git version library, you only need to clone it locally.
Example: git clone git: // github.com/someone/some_project.git some_project
The above command is to clone the remote repository of 'git: // github.com/someone/some_project.git' to the external some_projectdirectory.
Git init and git remote: This method is a little more complicated. When you create a local... the remaining full text>

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.