Git Learning Summary

Source: Internet
Author: User
Tags git commands

recently learned to learn git, summed up a little bit about the use of GIT commands and problems encountered
git is known to be the most advanced distributed version control system in the world today. The following is a git usage knowledge
What is the main difference between SVN and git?
talking about git naturally think of svn, I have just access to the version Control tool is SVN,SVN is a centralized version control system, Repository is centralized on the central server , when working, first from the central server where to get the latest version, after the work, You need to push the work you've done to the central server. Central server is like a picture library, you have to change a book, you must first borrow from the library, and then go home to change their own, changed, and then put back to the gallery. Centralized version control system must be networked to work, if the LAN can also, the bandwidth is large enough, fast enough, if under the Internet, if the speed is slow, it will delay the matter.
git is a distributed version control system, it does not have a central server, everyone's computer is a full version of the library, when the work is not required to network, because the version is on their own computer. Since everyone's computer has a full repository, how do people collaborate? For example, they changed the file a on the computer, the other people also on the computer changed the file a, at this time, you two only need to put their changes to each other, you can see each other's changes.
compared with centralized version control system, the security of Distributed version control system is much higher, because everyone's computer has a complete version of the library, a person's computer is broken do not matter, casually from other people to copy one. Centralized version control system central server if there is a problem, everyone can not work.
The basic common commands for Git are:
ii. Common git commands

--File directory Operations Command

1 mkdir * *: Create an empty directory * * refers to directory name 2pwd:      Displays the path to the current directory.  3 Cat * *     View * * file contents 4 git rm * *  Delete * * file

--git initialization operation

1 git init   turns the current directory into a manageable git repository, generating hidden.  git files.  2 git remote add origin https://github.com/git/librarysystem.git  pushes the contents of the local repository to the GitHub repository.  3clone [email protected]:michaelliao/gitskills. git   clone from remote library 4 git add * *           add xx file to Staging area.  5 git commit–m "* *"  commits a file –m followed by a comment.

--View commands

1 git status        view warehouse status 2 git diff  * *       view xx file modified those contents    3log           View History 4 git reflog       View history's version ID (record every command you have, whether or not it's submitted)5  Log --pretty=oneline If the amount of information is too much to make a better list display

--Version fallback

1 Reset  Reset  --hard head~ fallback to previous version 2  reset –hard head~80  reset --hard version number)

--Branch management

 1  git push–u (first time with-u not needed later) Origin master Push the current master branch to the remote library  2  3  git branch name Create branch  4  git checkout-** undo all changes to the xx file in the workspace.  5  git checkout–b Dev Create dev branch and switch to Dev branch 
    6  7  8  git Merge Dev merges the Dev branch on the current branch  9  git push--set-upstream origin Dev commits the changes and Create a remote branch dev 

--Hidden files

1 git stash to       hide the current work and resume work after resuming the scene 2list   View all hidden files list 3git Stash apply recover hidden files, but content does not delete 4git stash drop  Delete file 5 git stash pop   recover files while deleting files

--View Remote library information  

1 git remote      to view information about a distant library 2 git remote–v   view Remote Library details


three, often error:
1:There is no tracking information for the current branch ...
The link relationship between local branch and remote branch is not created, with the command:
git branch--set-upstream branch-name origin/branch-name.

2: ![ Rejected] Dev, dev (non-fast-forward) ... Updates were rejected because the tip of your current branch
push failed because the latest commit of remote code conflicts with the commit you are trying to push, the workaround is simple, first use git pull to capture the latest commit from Origin/dev, then merge locally, resolve the conflict , and then push
    
3:CONFLICT (content): Merge CONFLICT in ...
this time git pull succeeds, but there is a conflict in the merge, which needs to be solved manually, and the workaround is the same as the conflict resolution in branch management. After resolving, submit, and then push:
    
4: You is not currently to a branch, so I cannot use any
workaround: Git checkout master

5:Your branch is behind ' Origin/master ' by 1 commits, and can be fast-forwarded.
The above display means that there is an update that has not yet reacted locally, possibly someone else has submitted something to the server.
you can use the git pull command to get these updates locally.

Iv. experience of experience:
1:The difference between git revert and git reset
starting to feel the same, but after the client and command-line window operation found a big difference, see an example: I first submit three times the three-way ID number is (15d5f70,a167eb1,8fbfe3f) as

then perform version fallback git reset–hard a167

instructions to perform git reset–hard * * Version fallback is to undo a commit, but the subsequent changes will be returned to staging area, as it shows a commit (by 1 commit)
similarly execute git revert–hard a167
git revert is a commit before rolling back with a new commit
in the rollback operation, the effect is the same. However, there is a difference when you continue to merge old versions of the previous version later. Revert is a commit that was preceded by a reverse commit "in and",As a result, when merging Old branch, this change will not occur again, but the reset is to delete some commits on some branch, and thus the oldBranch Merge again, these rollback commits should also be introduced.
get the conclusion:git reset is to move head backwards, and git revert is head moving forward,
Only the content of the new commit and the content to be revert is the opposite, which can counteract the content to be revert.

v. Common changes:
1: avoid entering user name and password for each commit
The reason is to use the HTTPS mode puh in Termail inside the git remote-v can see the shape of the return results
Origin Https://github.com/git/librarysystem.git (fetch)
origin Https://github.com/git/librarysystem.git (push)
here's how to change it to SSH.

1 1. git remote rm Origin 2 2. git remote add origin [email protected]:yu/demo. git 3

2:. Gitignore
the. Gitignore configuration file is used to configure files that do not need to be added to version management.
configuration Syntax:
"/" indicates the directory;
"*" wildcard with multiple characters;
        "?" Pass a single character
"[]" contains a list of matches for a single character;
        "!" Indicates that the matching file or directory is not ignored (tracked);
git matches the. Ignore profile in rows from top to bottom, meaning that if the previous rule matches a larger range, the subsequent rules will not take effect;
Example:
(1) foder/* ignores all content under directory Foder, whether it is the/foder/directory under the root directory or a subdirectory/list/foder/directory, is ignored.
(2)/foder/* Description: Ignore the root directory of the/foder/directory of the entire contents;
(3)/*
            !. Gitignore
!/fw/bin/
!/fw/sf/
Description: Ignores all content, but does not ignore. gitignore files,/fw/bin/and/fw/sf/directories in the root directory
Note the problem:
. gitignore files work only on files that have not yet been versioned, and if you have previously used git to include files that you want to ignore in the repository, it doesn't work.


Vi. topic of digression

Git- Version Control tool
git is Linus Torvalds in order to help manage Linux An open source version control software developed by the kernel.
torvalds started to develop Git as a transitional scheme to replace BitKeeper, the latter has been the main source code tool used by Linux kernel developers around the world. Some in the open source community felt that BitKeeper's license was not appropriate for the open-source community, so Torvalds decided to work on a more flexible version control system. Although Git was originally developed to assist the Linux kernel development process, we have found that Git is also used in many other free software projects. For example, recently migrated to Git, and many freedesktop projects migrated to Git.

Github -A Web site that provides user space to create a git repository, save a user some data documents or code such as


github can host a variety of git libraries and provide a web interface, but unlike other Unlike services such as SourceForge or Google code, GitHub's unique selling point is the simplicity of branching from another project. Contributing code to a project is simple: first click on the "Fork" button of the project site, then check out the code and add the changes to the code base you just separated, and finally request a code merge from the project owner through the built-in pull request mechanism. GitHub has already been called the code player's MySpace.

GitLab-git-based project management software
GitLab is an open source project for the warehouse management system. Use Git as a code management tool and build on this Web service. All three are git-based and can be said to be git derivatives.

Git Learning Summary

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.