Git common Command collation

Source: Internet
Author: User
Tags delete cache using git

To create a version library

$ mkdir Learngit

$ CD Learngit

$ pwd//used to display the current directory

Initialize a git repository using the git init command.

? Add text ? To a git repository in two steps:

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

The second step is to use the command git commit to complete.

To keep track of the status of your workspace, use the git status command.

If Git status tells you that a file has been modified, use Git diff to see what's changed.

Time Machine

The version that head points to is the current version, so git allows us to navigate between versions of history, using the command git reset--hard commit_id.

Before the shuttle, use git log to view the commit history to determine which version to fallback to.

To return to the future, use git reflog to view the command history to determine which version to go back to in the future.

Undo Changes

Scenario 1: When you mess up the contents of a file in your workspace and want to discard changes to the workspace directly, use the command git checkout-file.

Scenario 2: When you not only changed the contents of a file in the workspace, but also added to the staging area, want to discard the changes, two steps, the first step with the command git reset HEAD file, back to Scene 1, the second step by scene 1 operation.

Scenario 3: When an inappropriate modification to the repository has been submitted, you want to revoke this commit, refer to the version fallback section, but only if it is not pushed to the remote library.

git checkout--file can be modified by discarding the workspace:

Git checkout--in the file command--very important, not--becomes the "switch to another branch" command, and we will encounter the git checkout command again in later branch management.

$ git reset HEAD demo.txt lost cache changes

RM test.txt Delete workspace files

$ git RM test.txt Delete cache file

Remote Library

to associate a remote library, use the command git remote add origin [email protected]:p ath/repo-name.git;

Once associated, use the command Git push-u Origin master to push all the contents of the master branch for the first time;

Thereafter, after each local commit, whenever necessary, you can use the command GIT push Origin master to push the latest changes;

Remote Library cloning

To clone a warehouse, you must first know the address of the warehouse and then clone it using the git clone command.

GIT supports multiple protocols, including HTTPS, but the native GIT protocol supported by SSH is the fastest.

View branches: Git branch

Create a branch: Git branch <name>

Switch branches: git checkout <name>

Create + switch branches: git checkout-b <name>

Merge a branch to the current branch: git merge <name>

Merging branches, plus the--NO-FF parameter can be combined with the normal mode, the merged history has branches, can see that there has been a merger, and fast forward merge will not be seen to have been merged.

$ git merge--no-ff-m "merge with No-ff" Dev

Delete branch: Git branch-d <name>

Conflict

Use the git log--graph command to see the branching merge diagram.

$ git log--graph--pretty=oneline--abbrev-commit to view the branch consolidation situation

Bug Branch

When the work is not finished, first put the work site git stash , and then to fix the bug, repair, then git stash pop, back to the job site.

Use the Git stash List command to see:

Git puts stash content somewhere, but there are two ways to recover it:

One is to use git stash apply recovery, but after recovery, stash content is not deleted, you need to use git stash drop to delete;

Another way is to use git stash pop, restore the stash content also deleted:

Can stash multiple times, restore, first with Git stash list view, and then restore the specified stash, with the command:

$ git stash apply [email protected]{0}

Function Branch

To develop a new feature, it is better to create a new branch;

If you want to discard a branch that has not been merged, you can use git branch-d <name> forcibly delete it.

View Remote library information, using git remote-v;

Local new branches are not visible to others if they are not pushed to the remote;

Push the branch from the local, use GIT push Origin branch-name, if push fails, first crawl the remote new commit with git pull;

Create local and remote branches corresponding to the branch, using git checkout-b branch-name origin/branch-name, local and remote branch names are best consistent;

Establish the Association of local and remote branches, using Git branch--set-upstream branch-name origin/branch-name;

From a remote crawl branch, use git pull, and if there is a conflict, deal with the conflict first.

Label

Command git tag <name> to create a new tag, the default is head, you can also specify a commit ID;

Git tag-a <tagname>-M "Blablabla ..." to specify tag information;

command git tag to view all tags.

Command GIT push origin <tagname> can push a local tag;

Command GIT push origin--tags to push all the local tags that have not been pushed;

Command git tag-d <tagname> can delete a local tag;

Command git push origin:refs/tags/<tagname> to delete a remote tag.

Git tag-s <tagname>-M "Blablabla ..." can be signed with PGP tag;

When you omit certain files, you need to write. Gitignore;

The. gitignore file itself is put into the repository and can be versioned for. Gitignore!

Configure aliases

$ git config--global alias.st status

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 '

Building a git server is easy, usually in 10 minutes;

To facilitate the management of public key, with Gitosis;

To be as perverted as SVN to control permissions, with Gitolite.

The original is Liaoche git tutorial, Link: http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000

Git common Command collation

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.