Git usage Summary

Source: Internet
Author: User
Tags using git

Git usage summary git is currently the most popular code management software, including Linux kernel source code and android source code are managed by git. Git is highly efficient and clean, and the generated intermediate file does not affect the code. It has a great advantage over SVN. At present, git is also used to manage the source code. Here, we will give a brief look at the Usage Details and commands. Install gitsudo apt-get install git-core in ubuntu to create a unified account to manage git projects, avoid conflicts later due to the submission of modifications by multiple users. sudo adduser gitsudo passwd git initializes the mkdir projectcm projectgit init warehouse. At this time, there will be more in the project file. git folder to manage git add. (A snapshot is required for the current project.) git commit-m "xxxxxx" at this time, the remote git repository has been established and local clone remote library git clone git @ ip: /source/destgit config -- global user. name "your name" git config -- global user. modify the file by email "email @ xxxx" and submit * Add new or modified files To git index: git add file1 file2 saves the index content to the git library before git commit is submitted. view the modification status: git diff -- cached or git status branch Management: git branch view branch git branch (create branch) git checkout branching switch to branching branch is equivalent to git ckeckout-B branch1git merge branching merge to branching branch git branch-d branching Delete branch branching, follow the prompts to modify the error git branch-D branching force Delete submit local branch branching to remote repository similarly as Branching branch git push origin branching Delete branching branch git push origin in remote Repository: Branching encountered the following error when using git to push code to the repository: [remote rejected] master-> master (branch is currently checked out) remote: error: refusing to update checked out branch: refs/heads/masterremote: error: By default, updating the current branch in a non-bare repositoryremote: error: is denied, because it will make the index and work tree inconsistent. This is because git rejects the push operation by default and needs to be set and modified. add the following code after the git/config file: [receive] denyCurrent Branch = communication between ignore developers (hereinafter referred to as local) and servers (remote); (the following are all local operations) git push remote project path local Branch name: remote branch name. when there is a local modification file: first submit the modification, enter git commit-am "modification description", then push the modification to the branch corresponding to the server, and enter: git push origin test: master // merge the local test branch to the master branch on the server. git push origin test: test // merge the local test branch to the test branch on the server. the server project path automatically defined in the git/config file can be viewed by yourself.) Note that git push does not automatically Merge files. Therefore, if a conflict occurs during git push, it will be forcibly overwritten by the content of the subsequent push file, and there is no prompt. If git init Initialization is used, the Directory of the remote Repository also contains the work tree. When the local repository is pushed to the remote repository, if the remote repository is on the push Branch (if it is not on the push branch at the time, there is no problem), the push result will not be reflected on the work tree, that is to say, the corresponding file in the remote repository directory is still the previous content. You must use git reset -- hard to see the pushed content B. when a new branch exists locally: Submit the modifications to the new branch, then push the test1 Branch created locally to the server, and enter: git push origin test1: remote branch name // push the new local test1 branch to the server to view the server. A new branch is added to the server. If the remote branch name is not entered, the new branch name on the server is the same as the local branch name (test1). If you enter the remote branch name, the new branch name on the server is the branch name entered. c. delete remote branch: If the left branch is empty, it will be deleted: The remote branch on the right. Input: git push origin: test // remote test will be deleted, but it will be saved locally. Note that, git push does not seem to automatically Merge files. Therefore, if a conflict occurs during git push, it will be forcibly overwritten by the content of the subsequent push file, and there is no prompt. If git init Initialization is used, the Directory of the remote Repository also contains the work tree. When the local repository is pushed to the remote repository, if the remote repository is on the push Branch (if the branch is not pushed at the time, there is no problem), the push result will not be reflected on the work tree, that is to say, the corresponding file in the remote repository directory is still the previous content. You must use git reset -- hard to see the pushed content B. when a new branch exists locally: Submit the modifications to the new branch, then push the test1 Branch created locally to the server, and enter: git push origin test1: remote branch name // push the new local test1 branch to the server to view the server. A new branch is added to the server. If the remote branch name is not entered, the new branch name on the server is the same as the local branch name (test1). If you enter the remote branch name, the new branch name on the server is the branch name entered. c. delete remote branch: If the left branch is empty, the remote Branch, input: git push origin: test // remote test will be deleted, but local git pull remote project path remote branch name: local branch name. when a file or patch is modified on the server, the file or patch must be submitted on the server first: pull the modification to the local branch, and enter: git pull origin test: master // merge server-side test branch to local master branch git pull origin test: test // merge server-side test branch to local test branch Note: if there is a conflict during the merge, then, manually modify the conflict and commit until there is no conflict before merging. B. when a new branch exists on the server side: Submit the modifications to the new branch, and then pull the test1 Branch created on the server side to the local machine. Input: git pull origin test1: local branch name // pull the new test1 branch of the server to the local machine to view the local machine. New Branch. Note: You must enter the name of the local branch. Otherwise, the local branch cannot be viewed (the cause is to be queried). view the Log: git loggit log-p display patchgit log -- stat display a summary of the changes git log -- graph only displays the current branch git log -- graph -- all display all branch git logs -- graph -- all -- decorate: displays the branch name git log -- pretty = oneline, the log format output by short, full, and fuller is different from that output by git log -- pretty = format: "% h-% an, % ar: % s. For other -- pretty options and specific format formats, refer to the pretty format section in git log -- help. Git log -- follow file. c is very interesting, especially when file. c is moved. We usually move a file to a directory. In this case, the git log cannot display the records before the directory is moved. Add -- follow. Git log filtering git log-2-p displays the logs and diffgit logs of the last two commit times -- author = "Author Name" filter the loggit logs of specific authors -- since = "2012-2-23 "-- before = "2012-2-24" filtering time segment git log -- grep = "key word" Search for the keyword git log branch in the message of commit -- not master to view on branch, but not on the master. Git undo: git checkout -- filename undo modification, restore to the version before modification git reset HEAD filename cancel temporary file back to the status of the modified unsaved file back to the specified version, clear all information after this version: $ git reset -- hard HEAD ^ (you can specify commit here for query) this will roll back the content of the current work branch to the "HEAD ^" version. Note that this command will not only remove the current modification, in addition, all "commit" from "HEAD ^" will be deleted (the HEAD ^ version itself is reserved as the current HEAD). If the current branch is a unique branch, after running this command, modifications made after "HEAD ^" will be completely lost (of course, you can use "pull" to pull the previous HEAD back, however, local modifications that have not been submitted cannot be found ); in addition, if you execute this command on a public branch, other developers will perform this cleanup operation during pull. If you do not add the -- hard option, this command may fail due to modifications to the current HEAD. Roll back to the specified version and submit it as the new version (keep all information after the version ): $ git revert HEAD ^ this will only roll back the content to the version earlier than HEAD ^ (that is, HEAD ^), and then submit the content as a new HEAD, the original HEAD is changed to HEAD ^ (that is, the commit of the version after HEAD ^ is retained in the database, instead of being completely cleared as "reset ). Here, after running the command, an edit window is opened to allow you to edit the submitted log information. If you exit the operation, the submitted log information is submitted directly, or the "revert" command also has the option of not editing the submitted log information. HEAD: indicates the latest commit. (Latest Version) MERGE_HEAD: if it is a commit generated by merge, it indicates another parent branch except the HEAD. FETCH_HEAD: the object and ref information obtained using git-fetch are stored here, which is prepared for future git-merge. HEAD ^: HEAD parents' information HEAD ~ 4: indicates the four generations of HEAD information HEAD ^ 1: indicates the information of the first parent of the HEAD (the same as HEAD ^) HEAD ^ 2: indicates the information of the second parent of the HEAD COMMIT_EDITMSG: the submission information for the last commit.

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.