Git manual Query

Source: Internet
Author: User
Tags gnupg gpg using git

1. Create a version library

Use the GIT init command to turn this directory into a repository that git can manage;

Add files to a git repository in two steps

The first step: git add <file>, note that you can use it repeatedly, add multiple files, such as git add a.js b.html c.css

Step two: Git commit-m "commit information" such as git common-m fix bug

2. Version fallback

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

Before the shuttle, use git log to view the commit history, in order to determine which version to back to;//press Q to exit

To go back to the latest version, use Git reflog to view the command history to determine which version to advance to;//press Q to exit

3. deleting files

Command git rm is used to delete a file such as Git rm a.js, which needs to be common again after deletion

4. Workspace (working Directory) version Library (Repository)

Know the status of the workspace: using the git status command;

Git diff can see the specific changes;

5. Branch

View branches: Git branch

Create a branch: Git branch <name>

Switch branches: git checkout <name>

Create + switch branch git checkout-b <name>

Merge a branch into the current branch git merge <name>

Delete branch git branch-d <name>

6. Multi-person collaboration

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.

7. Conflict resolution

When git cannot merge branches automatically, you must resolve conflicts first. After resolving the conflict, submit again, and the merge is complete.

You can see the branch merge diagram with the git log--graph command.

8. Branching policy

The GIT branch is very powerful and should be fully applied in team development.

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.

9.Bug Branch

When fixing a bug, we will fix it by creating a new bug branch, then merging and finally deleting;

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.

10.Feature Branch

Develop a new feature, and finally 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.

11.tag

1. Create a label

(Signature using PGP signature, therefore, must first install GPG (GnuPG), if not found GPG, or no GPG key pair, will be error;

Please refer to the GNUPG Help documentation to configure key and then use the command git show <tagname> to see the PGP signature information)

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;

(tbd) git tag-s <tagname>-M "Blablabla ..." can be signed with PGP tag;

git tag can see all the tags.

2. Operation label

Git push origin <tagname> can push a local tag;

Git push origin--tags can push all the local tags that have not been pushed;

Git tag-d <tagname> can delete a local tag;

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

12. Remote Storage

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

After the association, using the command Git push-u Origin master to push all the contents of the master branch for the first time, after each local commit, you can use the command GIT push Origin master to push the latest changes as necessary.

To clone a warehouse, you must first know the address of the warehouse and then use the git clone command to clone

GIT supports multiple protocols, including HTTPS, but native git protocols supported via SSH are faster

Git manual Query

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.