Git usage summary

Source: Internet
Author: User
Git usage summary git is currently the most popular code management software, including Linuxkernel 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... 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.
Related Article

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.