Programmers can organize git skills within one year, and programmers can have git skills within one year.

Source: Internet
Author: User

Programmers can organize git skills within one year, and programmers can have git skills within one year.

I have been using git for one year. The following is my summary of git usage over the past year, covering the vast majority of daily usage scenarios. Well, it may take at least a year to sort out and share it with you. If you don't understand it, you can reply to it.

Create and use git ssh key

First, set the git user name and email:

123 12git config --global user.name "xxx"git config --global user.email "xxx@gmail.com"

View git Configuration:

1 1git config --list

Then generate the SHH key:

Check whether an ssh key is available:

1 1cd ~/.ssh

If no key exists, this folder is not available. If yes, the backup is deleted.

Survival key:

1 1ssh-keygen -t rsa -C "xxx@gmail.com"

Press 3 and press Enter. If the password is empty, the key is generally not used.

Finally, two files are obtained: id_rsa and id_rsa.pub.

Note: Do not change the key generation. If the key has been generated ~ /. Search for the ssh folder.

Git change project address

123 12git remote set-url origin git@192.168.6.70:res_dev_group/test.gitgit remote -v

View the modification history of a file

1234 12git log -- pretty = oneline file name # display modification historyGit show 356f6def9d3fb7f3b9032ff5aa4b9110d4cca87e # view changesGit push error: warning: push.default is unset;

The 'matching 'parameter is the default behavior of Git 1.x. It means that if you execute git push but do not specify a branch, it will push all your local branches to the matched branches in the remote repository. Git 2.x is simple by default, which means that when no branch is specified for executing git push, only the current branch will be pushed to the code you obtained using git pull.

Modify the behavior of git push as prompted:

1 1git config --global push.default matching

Execute git push again to solve the problem.

Use git submodule to pull sub-project code

During the development process, some common parts are often to be extracted and made into a public library for use by other projects. Version Management of the public code library is troublesome. Today, I accidentally discovered the git submodule command of git, and the previous problem was solved.

1. Add

Add a submodule to the current project. The command is as follows:

1git submodule add repository address path

The repository address refers to the sub-module repository address, and the path refers to the path where the sub-module is placed under the current project.

Note: The path cannot end with a slash (which may cause the modification to fail) or be an existing Directory of an existing project (cannot be used for Clone)

After the command is executed, a file named ". gitmodules" is generated under the root path of the current project, which records the information of the sub-module. After the sub-module is added, add the folder where the sub-module is located to the project.

2. Delete

It is a little troublesome to delete the submodule: first, delete the corresponding configuration information in the ". gitmodules" file. Then, run the git rm-cached command to delete the file of the sub-module from git.

The downloaded project has a submodule.

When a project cloned by git contains a submodule, the submodule content is not automatically downloaded at the initial time. In this case, you only need to execute the following command:

1git submodule update -- init -- recursive

You can download the sub-module content before the project does not lack the corresponding files.

Cancel git add File

In general use of git, if you find that the file you do not want to submit is added to the index and want to roll back and cancel it, you can run the command: git reset HEAD ..., At the same time, after git add is complete, git will prompt accordingly.

1 http://blog.csdn.net/yaoming168/article/details/38777763

Git:

Delete file tracking and delete file file1git rm file1 in the file system

After submitting the delete operation, git will not manage the file git commit.

Delete a file trace but do not delete file1git rm-cached file1 in the file system

After submitting the delete action, git does not manage the file. But there is still file1 in the file system. Git commit

Version rollback

Version rollback is used to restore the old version after an online system error occurs.

Git reset-hard 248cba8e77231601d1189e3576dc096c8986ae5

All files are rolled back. If you regret rolling back, you can use git pull.

Historical version Comparison

View the git log

View the submitted content of a previous version git show 4ebd4bbc3ed321d01484a4ed206f18ce2ebde5ca. The detailed modification code of the version is displayed here.

Compare different versions of git diff c0f28a2ec490236caa13dec0e8ea826583b49b7a 2e476412c34a63b213b735e5a6d90cd05b014c33

Http://blog.csdn.net/lxlzhn/article/details/9356473

Meaning and Management of branches

Creating a branch can avoid the impact on the main branch after code is submitted, and also give you a relatively independent development environment. Branch is of great significance.

Create and switch the branch. Only after the code is submitted can the branch code git checkout-B new_branch be pulled from other machines.

View git branch of the current branch

Switch to the master branch git checkout master

Merge branches to the current branch git merge new_branch. The merge branch operation is to merge from new_branch to the master branch, and the current environment is in the master branch.

Delete branch git branch-d new_branch

Git conflict file editing

The conflicting file conflicts are as follows:

12345678910111213 1234567a123<<<<<<< HEADb789=======b45678910>>>>>>> 6853e5ff961e684d3a6c02d4d06183b5ff330dccc

The content between <(7 <) and ====== is my modification, the content between ========>>>>>>> is modified by others.

At this time, no other junk files have been generated.

You need to merge the code and then repeat the code submission process.

Unsuccessful code submission process

An error may occur after git push because someone else has submitted the code and your local code library version is not up to date.

In this case, you need to first run the git pull code and then check whether there is any file conflict.

If there is no file conflict, You need to repeat the code submission process add-> commit-> push.

Resolving file conflicts is described later.

Git's smooth code submission process

View the modified file git status;

To carefully check the code git diff;

Add the modified file git add dirname1/filename1.py dirname2/filenam2.py. add the newly added file directly;

Add the modified log git commit-m "fixed: modified the logic of the uploaded file ";

Commit code git push. If the submission fails, the possible cause is that the local code library version is not the latest.

Understanding github's pull request

There is A warehouse called Repo. If you want to contribute code in, you need to Fork the Repo first, so you have a Repo A2 under your Github account ,. Then you work in this A2, such as Commit and push. Then you want the original repository Repo A to merge your work. You can initiate A Pull Request on Github, which means to Request the owner of Repo A to merge the branches from your A2. If it is approved and formally merged, you will contribute to project.

1 http://zhidao.baidu.com/question/1669154493305991627.html

Handle some errors

123456 "Pathspec 'branch' did not match any file (s) known to git." error123git checkout mastergit pullgit checkout new_branch

This error may occur when you use git to submit large files.

1234 error: RPC failed; result=22, HTTP code = 411fatal: The remote end hung up unexpectedlyfatal: The remote end hung up unexpectedlyEverything up-to-date

In this case, first change the git transmission byte limit.

1 1git config http.postBuffer 524288000

Another error may occur during transmission at this time.

1234 error: RPC failed; result=22, HTTP code = 413fatal: The remote end hung up unexpectedlyfatal: The remote end hung up unexpectedlyEverything up-to-date

These two errors look similar. One is 411, and the other is 413.

Add the key following this error.

First, key-keygen generates the key.

Then copy the generated key to the corresponding location under your account in git.

12 1git push ssh://192.168.64.250/eccp.git branch

Recommended reading:

Programming experience of senior programmers

Several important growth stages of programmers

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.