$git init $git add README $git add README $git add README $git commit -m 'first commit' And annotation information first commit $git remote add origin [email protected]/hellotest git / / to connect to a remote making project $git push -u origin master // Update local projects to github projectsCopy the code
Git is set to turn off wrapping
$ git config --global core.autocrlf false
Copy the code
To ensure that file newlines are used in a safe manner and avoid the mixing of Windows and Unix newlines, it is best to add this sentence
$ git config --global core.safecrlf true
Copy the code
Use the git tag
Git tag -a v0.2.1 -m '0.2.1 '# git tag -a v0.2.1 -m '0.2.1' # Git tag -d v0.2.1 git tag -d v0.2.9fbc3D0 git tag -d v0.2.9fbc3d0 Git tag # Check the tags in the current branchCopy the code
The git pull problem
You asked me to pull without telling me which branch you
want to merge with, and 'branch.content_api_zhangxu.merge' in
your configuration file does not tell me, either. Please
specify which branch you want to use on the command line and
try again (e.g. 'git pull ').
See git-pull(1) for details.
If you often merge with the same branch, you may want to
use something like the following in your configuration file:
[branch "content_api_zhangxu"]
remote =
merge =
[remote ""]
url =
fetch = See git-config(1) for details.
Copy the code
git pull origin new_branch
Copy the code
How do I iterate through and remove all.pyc files in a project
sudo find /tmp -name "*.pyc" | xargs rm -rf
Copy the code
Replace the/TMP directory with the working directory
This can also be used
To avoid another miscommit, create a. Gitignore file in the project and enter *. Pyc to filter the file
Git changes the project address
Git remote set-url origin [email protected]:res_dev_group/test.git git remote -vCopy the code
View the modification history of a file
Git log - change history git pretty = oneline filename # show show f6def9d3fb7f3b9032ff5aa4b9110d4cca87e # 356 to see changesCopy the code
Git push error Warning: push.default is unset
The ‘matching’ parameter is the default behavior of Git 1.x, meaning that if you do a Git push without specifying a branch, it will push all of your local branches to matching branches in the remote repository. Git 2.x defaults to simple, meaning that when you do a Git push without specifying a branch, only the current branch will be pushed to the code you fetched using Git pull.
Modify the behavior of git push as prompted:
Git config -- global push.default matchingCopy the code
Git push is done again
Git submodule uses pull project code
In the development process, there are often some common parts that want to be extracted into a common library for other projects to use, and the version management of the common code base is a troublesome thing. Git submodule: git submodule
To add a submodule to the current project, run the following command:
Git subModule add Repository address pathCopy the code
The warehouse address refers to the sub-module warehouse address, and the path refers to the path to place the sub-module under the current project. Note: The path cannot end with/(the modification will not take effect), and cannot be an existing directory of the existing project (it cannot be cloned successfully).
After the command is executed, a file named. Gitmodules is generated in the root path of the current project, which records information about submodules. After adding, add the folder where the submodule resides to the project.
Deleting submodules is a bit trickier: First, you need to delete the configuration information in the. Gitmodules file. Then, run git rm -cached to remove the file where the submodule resides from Git.
The downloaded project comes with a subModule
Git Clone will not download the subModule automatically, so you only need to run the following command:
git submodule update --init --recursive
Copy the code
The submodule content can be downloaded after the project will not lack the corresponding file.
Some mistakes
Pathspec ‘branch’ did not match any file(s) known to git
git checkout master
git pull
git checkout new_branch
Copy the code
This error can occur when you commit large files using Git
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
Copy the code
Change git’s transfer limit first
git config http.postBuffer 524288000
Copy the code
Then another error may occur during transmission
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
Copy the code
The two errors look similar; one is 411 and the other is 413
Add the key to the error below
First key-keygen generates the key
Then copy the generated key to the appropriate location under your account in Git
Git push SSH: / / 192.168.64.250 eccp git branchCopy the code
Git add file cancelled
In git’s general use, if you find an error and add the file you do not want to submit to index, you can use the command:
After git is added, git will also make a corresponding prompt.
Git reset
Git delete files
Delete file tracing and delete file file1 from the file system
Commit the delete action and Git will no longer manage the file
Delete file tracing but do not delete files in the file system
file1git rm --cached file1
Copy the code
Git no longer manages the file after committing the delete action, but file1 still exists on the file system
Version back
Version rollback This operation is used to restore the online system to an earlier version if a fault occurs.
git reset --hard 248cba8e77231601d1189e3576dc096c8986ae51
Copy the code
Git pull is the only way to roll back all files.
Historical version comparison
Git log View the submitted content of a historical version. You can see the detailed modification code of the version here.
git show 4ebd4bbc3ed321d01484a4ed206f18ce2ebde5ca
Copy the code
Compare different versions
git diff c0f28a2ec490236caa13dec0e8ea826583b49b7a 2e476412c34a63b213b735e5a6d90cd05b014c33
Copy the code
Git Common Commands and Scenarios (3
The meaning and management of branches
Creating a branch avoids the impact of committing code to the main branch, and gives you a relatively independent development environment. Branching is very important. Create and switch branches, commit code before pulling branch code on other machines
git checkout -b new_branch
Copy the code
View the current branch
Switch to the Master branch
Merge branches to the current branch. Merge branches from new_branch to the master branch. The current environment is in the master branch.
Delete the branch
Git conflicting file editing
Conflicting files collide as follows
a123
<<<<<<< HEAD
b789
=======
b45678910>>>>>>> 6853e5ff961e684d3a6c02d4d06183b5ff330dccc
Copy the code
Conflict tag < < < < < < < (7 “) and the = = = = = = = is my change, the content of the = = = = = = = > and > > > > > > is the content between the change of others. At this point, no other garbage files have been generated. You need to merge the code together and go through the code submission process again.
Bad code submission process
An error after a Git push could be caused by someone else committing code and making your native codebase version not up to date. You need to check for file conflicts after git pull. If there are no file conflicts, you need to go through the code submission process again add – > commit – > push. Resolving file conflicts is explained later.
Git has a smooth code submission process
View the modified file
Check the code for caution
Add the modified file, the newly added file is also directly add good
git add dirname1/filename1.py dirname2/filenam2.py
Copy the code
Add modified logs
Git commit -m "Fixed: fixed"Copy the code
Commit code git push if the commit fails because the local codebase version is not up to date.
Understand the Github pull Request
There’s A warehouse called Repo A. To contribute, you first Fork the Repo, so you have a Repo A2 under your Github account. And then you work under A2, commit, push, etc. Then you want the original repository Repo A to merge your work. You can make A Pull Request on Github, which means asking the owner of Repo A to merge branches from your A2. If approved and officially merged, you will have contributed to project A.
What does github pull Request stand for
Create and use git SSH keys
Start by setting git’s user name and email
git config --global user.name "xxx"
git config --global user.email "[email protected]"
Copy the code
Checking git Configuration
The SHH key is then generated
Run the CD ~/. SSH command to check whether there is an SSH key. If there is no SSH key, the folder does not exist
ssh-keygen -t rsa -C "[email protected]"
Copy the code
Press enter three times, the password is empty and you don’t normally use a key here. Finally got the two files: id_rsa and id_rsa pub note: don’t change the key generation, if have been generated to ~ /. SSH folder to find.