Create and use Git ssh key
First set up Git's user name and email:
git config--global user.name "xxx" git config--global user.email "[Email protected]"
To view the GIT configuration:
git config--list
Then generate the Shh key:
To see if you already have an SSH key:cd ~/.ssh
If there is no key then there will be no such folder, there is a backup to delete
Survival key:
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: The key generator should not be changed, if it has been generated to the ~/.ssh
folder down to find.
Git Change Project Address
git remote set-url origin [email protected]:res_dev_group/test.gitgit remote-v
View a file's modification history
git log–pretty=oneline file name # Show modification History
Git show 356f6def9d3fb7f3b9032ff5aa4b9110d4cca87e # view Changes
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:
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, I stumbled on the git git submodule
command, and the previous problem was solved.
Add to
To add submodule to the current project, the command is as follows:
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.
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
the project with Submodule, the initial time, the content of submodule will not be downloaded automatically, at this time, only need to execute the following command:
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 back up the cancellation, you can use the command: git reset HEAD <file>...
and git add after the completion of Git will do the corresponding prompt.
http://blog.csdn.net/yaoming168/article/details/38777763
git delete files:
Delete file trace and delete file in file system File1git rm file1
Commit the delete action you just made, and then git no longer manages the filegit 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 the versiongit reset --hard 248cba8e77231601d1189e3576dc096c8986ae51
Fallback is all files, if regret fallback can be git pull.
Historical version Comparison
View Logsgit log
View the submission for a historical version git show 4ebd4bbc3ed321d01484a4ed206f18ce2ebde5ca
, where you can see the detailed revision code for the version.
Compare different versionsgit 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, submit code before you can pull branch code from other machinesgit checkout -b new_branch
View Current Branchgit branch
Switch to Master Branchgit 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 Branchgit branch -d new_branch
git conflict file editing
Conflicting file conflicts are as follows
a123<<<<<<< headb789=======b45678910>>>>>>> 6853e5ff961e684d3a6c02d4d06183b5ff330dccc
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
git push
after the error, it may be that someone else has submitted the code, and your local code base version is not up to date.
At this point you need to git pull
check the code to see if there is a file conflict.
If there is no file conflict, you need to go through the code submission process again add —> commit —> push
.
Resolving file conflicts is said later.
Git successfully commits the code process
View the modified file git status
;
To check the code carefully git diff
;
Add the modified file git add dirname1/filename1.py dirname2/filenam2.py
, the new add the file is also directly add just fine;
Add the modified log git commit -m "fixed:修改了上传文件的逻辑"
;
Commit git push
The code if the submission 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
git checkout mastergit pullgit 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 everythin G up-to-date
In this case, first change the git transfer byte limit
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 everythin G 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.
git push ssh://192.168.64.250/eccp.git Branch
(reprint) Git common commands