Source: Pyper Welcome to share the original to Bole headlines
With Git for a year, here's my summary of git usage for the year, covering most of the scenes in everyday use. Well, at least for a year, put together to share to everyone, do not understand the place can reply to exchange.
Create and use Git ssh key
First set up Git's user name and email:
12 |
git config --global user.name "xxx" git config --global user.email "[email protected]" |
To view the GIT configuration:
Then generate the Shh key:
To see if you already have an SSH key:
If there is no key then there will be no such folder, there is a backup to delete
Survival key:
1 |
ssh-keygen -t rsa -C "[email protected]" |
Press 3 Enter, password is empty the key is generally not used here.
Finally, two files were obtained: Id_rsa and Id_rsa.pub
Note: Do not change the key generation, if it has been generated to the ~/.ssh folder down to find.
Git Change Project Address
12 |
git remote set -url origin [email protected] 192.168 . 6.70 :res_dev_group/test.git git remote -v |
View a file's modification history
12 |
git log --pretty=oneline 文件名 # 显示修改历史 git show 356f6def9d3fb7f3b9032ff5aa4b9110d4cca87e # 查看更改 |
git push times wrong warning:push.default is unset;
The ' matching ' parameter is the default behavior of Git 1.x, which means that if you perform a git push without specifying a branch, it will push all your local branches to the corresponding matching branch in the remote repository. The default for Git 2.x is simple, meaning that when you do not specify a branch for git push, only the current branch will be push to the code you get using git pull.
As prompted, modify the behavior of the GIT push:
1 |
git config --global push. default matching |
Execute the git push again to be resolved.
Git submodule using the Pull sub project code
In the development process, there are often some common parts of the hope to be extracted into a public library to provide for other projects to use, and the Public Code library version management is a troublesome thing. Today, the git git submodule command was accidentally discovered, and the previous problem was solved.
1. Add
To add submodule to the current project, the command is as follows:
1 |
git submodule add 仓库地址 路径 |
Where the warehouse address refers to the sub-module warehouse address, the path refers to the sub-module is placed under the current project path.
Note: The path cannot be in/end (will cause the modification not to take effect), cannot be the existing project already has the directory (cannot shun the Clone)
When the command executes, a file named ". Gitmodules" is generated under the current project root path, which records the submodule information. Once added, add the folder that contains the submodule to the project.
2. Delete
Submodule's removal is a little tricky: first, remove the configuration information in the ". Gitmodules" file. Then, execute the git rm–cached command to remove the file that contains the submodule from Git.
Download the project with Submodule
When using Git clone down the project with Submodule, the initial time, the Submodule content is not automatically downloaded, at this time, only need to execute the following command:
1 |
git submodule update --init --recursive |
You can download the contents of the Submodule after the project will not be missing the corresponding files.
git Add File Cancel
In the general use of Git, if you find that you do not want to submit the file add to the index, you want to fallback cancellation, you can use the command: Git reset HEAD <file>, ..., and git add after the completion of Git will also do the corresponding prompt.
http://blog.csdn.net/yaoming168/article/details/38777763
git delete files:
Delete file tracking and delete files in file system File1git RM file1
Commit the delete action you just made, then git no longer manages the file git commit
Deleting file traces but not deleting files in the file system File1git rm–cached file1
Commit the delete action you just made, and then git no longer manages the file. However, there are still file1 in the file system. Git commit
Version fallback
Version fallback is used to recover an older version of an issue after a problem occurs on the online system.
Fallback to version of Git Reset–hard 248cba8e77231601d1189e3576dc096c8986ae5
Fallback is all files, if regret fallback can be git pull.
Historical version Comparison
View logs git log
View submissions for a historical version git show 4ebd4bbc3ed321d01484a4ed206f18ce2ebde5ca, where you can see the detailed revision code for the version.
Compare different versions of Git diff c0f28a2ec490236caa13dec0e8ea826583b49b7a 2e476412c34a63b213b735e5a6d90cd05b014c33
http://blog.csdn.net/lxlzhn/article/details/9356473
The meaning and management of branch
Creating a branch avoids the impact on the main branch after the code is committed, and also gives you a relatively independent development environment. Branching is of great significance.
Create and switch branches, commit code before you can pull the branch code git checkout-b on other machines new_branch
View current Branch Git branch
Switch to Master branch git checkout Master
Merging branches into the current branch git merge new_branch, the merge branch is merged 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
Conflicting file conflicts are as follows
1234567 |
a123 <<<<<<< HEAD b789 ======= b45678910 >>>>>>> 6853e5ff961e684d3a6c02d4d06183b5ff330dcc c |
The content between conflict marker <<<<<<< (7 <) and ======= is my modification, and the content between ======= and >>>>>>> is someone else's modification.
At this point, no other junk files have been generated.
You need to merge the code and go through the code submission process again.
The code submission process is not smooth
An error after git push may be because someone else has submitted the code, and your local code base version is not up to date.
You will need to check for file conflicts after you have git pull code first.
There is no file conflict, you need to go through the code submission process add-> commit-> push.
Resolving file conflicts is said later.
Git successfully commits the code process
View the modified file git status;
In order to carefully check the code git diff;
Add modified file git add dirname1/filename1.py dirname2/filenam2.py, the newly added file is also directly add just fine;
Add modified log git commit-m "fixed: modified the logic of uploading files";
Commit the code to git push if the commit fails because the local code base version is not up-to-date.
Understanding GitHub's Pull Request
There is a warehouse, called Repo A. If you want to contribute to the code, first fork this repo, so in your GitHub account has a repo A2,. Then you work under this A2, Commit,push and so on. Then you want the original warehouse repo A to merge your work, you can launch a pull request on GitHub, which means request repo A's owner to merge branches from your A2. If it is approved and formally merged, then you contribute to project A.
Http://zhidao.baidu.com/question/1669154493305991627.html
Some error handling
"Pathspec ' branch ' didn't ' match any file (s) known to Git." Error
123 |
git checkout master git pull git checkout new_branch |
This error may occur when using Git to submit larger files
Error:rpc failed; result=22, HTTP code = 411
Fatal:the remote end hung up unexpectedly
Fatal:the remote end hung up unexpectedly
Everything up-to-date
In this case, first change the git transfer byte limit
1 |
git config http.postBuffer 524288000 |
And then at this point in the transmission there may be another error
Error:rpc failed; result=22, HTTP code = 413
Fatal:the remote end hung up unexpectedly
Fatal:the remote end hung up unexpectedly
Everything up-to-date
These two errors look similar, one is 411, one is 413
The next error is to add the key.
First Key-keygen generate the key
Then copy the generated key to the appropriate location under your own account in Git.
1 |
git push ssh: //192.168.64.250/eccp.git branch |
These git skills are enough for you for a year.