Common git commands

Source: Internet
Author: User
Tags tagname using git git commands

Common git commands

This article is to learn git when the note excerpt, see: Http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/

    • To create a version library
Git init
    • Add Files to Repository
git Add File ...
    • Submit the file to the warehouse
git commit-m "description"
    • View current warehouse Status
git status
    • View version Differences
git diff file name
    • Version fallback
--pretty=Oneline with head indicates that the previous version of the current version is Head^, the previous version is head^^ on the 100 version write 100 ^ more easy to count, so written head~100  --Hardcommit_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. 
    • Workspaces and Staging Area

workspace git add--> Staging Area -- git commit à Submit to Branch

  Note:git commit simply submits the contents of the staging area to the branch.

    • Undo Changes
Discard workspace Modifications: git checkout--file "note"--"if not then switch to another branch." Undo Staging Area modification: Git reset HEAD file "Undo Staging Area changes (Unstage) and back to workspace"
    • deleting files
git rm file name-->git Commit
    • Cloning from a remote repository
git clone giturl
    • Branch Management
    • Create and switch to a branch
git checkout-b devgit Checkout command plus -'dev'
    • Merging branches
git merge Dev
<name><name> Create + Toggle Branch: Git checkout-b <name><name>-D <name>
    • Resolve Conflicts

Git uses <<<<<<<,=======,>>>>>>> to mark different branches of content

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

Use the git log--graph command to see the branch merge diagram

git log--graph--pretty=oneline--abbrev-commit
    • Branch management policies

Typically, when merging branches,Git uses Fast forward mode if possible, but in this mode, the branch information is discarded when the branch is deleted.

Note   The--NO-FF parameter, which means that Fast forwardis disabled:

" Merge with No-ff the Dev

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.

First of all, the master branch should be very stable, that is, only to release the new version, usually do not work on it;

So where do you work? Work on the Dev branch, that is, the dev branch is unstable, at some point, such as when the 1.0 version is released, then merge the Dev branch to master and release the 1.0 version in the Master branch ;

You and your little friends each work on the Dev branch, and everyone has their own branch, and it's time to merge on the Dev branch.

So, the branch of teamwork looks like this:

  

    • Bug Branch

When a bug needs to be repaired urgently, the new feature is being developed. At this point, through a git stash function, the current work site can be " stored " , and so on after the resumption of the site to continue to work .

Git stash
View Storage area code list git stash list recovery store code to workspace recovery: git stash apply delete: Git stash drop recovery and delete: Git stash pop
    • Feature 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.

    • Multi-person collaboration
1-v2. Push branch Git push Origin master3-B dev origin/  " Add xxxxx " If the push fails, first grab the latest commit from Origin/dev with git pull, then merge locally, resolve the conflict, and then push: Specify a link to the local dev branch and the remote Origin/dev branch, as prompted, Set Dev and origin/--set-upstream Dev origin/branch Name
    • The working mode of multi-person collaboration is usually this:
1. First, you can try to push Origin branch-with Gitname pushes its own changes;2If the push fails, because the remote branch is newer than your local update, you need to first try to merge with git pull;3If there is a conflict in the merge, resolve the conflict and submit it locally;4If there is no conflict or resolves the conflict, then use Git to push Origin branch-name push will be successful! If Git pull hints "No tracking information", then the link relationship between the local branch and the remote branch is not created, using the command git branch--set-upstream Branch-name origin/branch-name. This is a multi-person collaborative mode of work, once familiar with, it is very simple. A summary? View remote library information using git remote-v;? A locally-created branch is not visible to others if it is not pushed to the remote; Push branch from local, use Git push Origin branch-name, if the push fails, use GIT pull to fetch the remote new commit first, and then create the branch that corresponds to the remote branch locally, using git checkout-B branch-name origin/branch-name, the names of local and remote branches are best consistent; create associations for local and remote branches, using GIT branch--set-upstream Branch-name origin/branch-Name: Crawl branches from the remote, use Git pull, and if there is a conflict, deal with the conflict first. 
Label Management
    • Create a label
ID"blablabla ... "  "blablabla ... "  <tagname> View label information
    • Action Label
-D v0. 1  <tagname>--tags Delete remote tag git push origin:refs/tags/v0. 9  <tagname>---D <tagname> can delete a local tag;? command git push origin:refs/tags/ <tagname> can delete a remote label.
    • Using GitHub

True----The settings of global user.email email and so on. 

    • Ignoring special files
? 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
Ready to be perfected
build a git server

Ready to be perfected

Common git commands

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.