1. Go to station B to watch video learning, only watch the first 39 episodes:
01-Git Overview (Git History)_哔哩哔哩_bilibili
2. Learn the use of Linux system text editor
Vi editor operation instruction sharing (baidu.com)
(13 messages) The use of nano editor_SudekiMing's Blog-CSDN Blog
Windows download and install
Git official download address:
Git - Downloading Package
installation diagram:
https://www.cnblogs.com/ximiaomiao/p/7140456.html
Linux download and install
sudo apt install git git command under
windows is consistent with Linux
git commands
git init initializes the warehouse
git clone https:// clone repository
git status View warehouse status
git add <file/name> Add files to the temporary storage area
git commit -m "file information" to submit changed files to the warehouse
git rm <file_name> deletes the file, then submits, and the version warehouse is also deleted
git config --list View username and email
git checkout -b <branch name> #Create a new branch
git branch #View branch
git rm -r --cached <file name> #Delete remote files or folders
git push origin --delete <branch name> #Delete remote branch
git branch -d <branch name> #delete local branch
git remote -v #display remote warehouse
git merge <branch name> #merge branch
git pull # pull, usually two people modify a branch at the same time, if others submit first
git rebase #rebase git
log #view historical submission
git checkout <commit sequence> #roll back to historical version
git reflog # record every command
git branch <new branch name > <serial number> #If you change the code after going back to the historical version and want to submit again, you can switch to the latest version, and then use this command line to create a new branch
storehouse
View the status of the file git status
Add the file to the temporary storage area git add <file_name> cancel adding git reset <file_name>
Submit to the local warehouse git commit -m ""
If the modified file wants to be submitted to the warehouse, it must first be added to the temporary storage area
git commit -a -m "" Add to the staging area and submit to the warehouse
Files are added to the ignore list, no versioning required. Create a .gitignore file and list the file suffixes to be ignored Command: touch .gitignore
View remote warehouse git remote
The newly created local warehouse needs to be associated with a remote warehouse before it can be pushed, and multiple remote warehouses can be associated
Associate remote warehouse git remote add origin < https://>
Cloning the warehouse will copy the historical version and log information together
git remote rm removes the record of the remote warehouse from the local
fetch fetch pull pull merge merge
git fetch origin master fetches the latest version from the remote warehouse to the local warehouse, it will not automatically merge, and needs to be manually merged into the workspace, git merge origin master
git pull origin master gets the latest version from the remote warehouse and merges it into the local warehouse,
If the local warehouse is not cloned and there are files, an error will be reported, and parameters need to be added: git pull origin master --allow-unrelated-histories
git push origin master pushes the local warehouse to the remote warehouse
the branch
view branch
List all branches git branch -a
List all local branches git branch
List all remote branches git branch -r
create branch
git branch <name>
Created based on the current branch, so generally create a new branch in the main branch
Switch branch git checkout <name>
Push the new branch to the remote warehouse git push origin <name>
merge branch
Enter the main branch and execute git merge <name>
When the two branches are merged, an error will be reported for different modifications of the same file. You need to modify the file yourself, then git add <modified file name>, indicating that the conflict has been resolved, then submit it to the local warehouse, and finally push the branch to the remote warehouse
Before merging the changes, you can use the following command to preview the differences between the two branches:
git diff <source_branch> <target_branch>
delete local branch
git branch -d <name> , force delete: git branch -D <name> , not recommended
Delete the remote warehouse branch git push origin -d <name>
Label
Tags are often used as version name identification
git tag <name> creates a tag
git tag list all tags
git show <name> view label information
git push origin <name> Push tags to remote warehouse
git tag -d [tag] delete local tags
git push origin :refs/tags/[tag]
Check out tag: create a new branch pointing to a certain tag, this branch is based on that version,
Command: git checkout -b [branch] [tag]
In ubuntu code version management process
first step:
Install the git command
sudo apt-get install git
Specify username and email
If it is a private computer, use the pinyin of your name as user.name, and your email address as user.email
If it is a public small computer, use feihu as user.name and 123456@jqr as user.email
$ git config --global user.name "Your Name"
$ git config --global user.email "[email protected]"
Then go to the code workspace and execute the command git init to initialize the local warehouse. If you have .git, you don’t need to execute it
(If you can't see .git, press Ctrl + H to show hidden files)
git remote View the remote warehouse, if there is no origin, add the remote warehouse: git remote add origin < https://gitee.com/username/warehouse name/tree/branch> to associate
Step two:
During the development process, if others on the same branch modify the code of the remote warehouse. We can use git pull to pull the remote code, and then we can synchronize the latest modified code of others to our local workspace.
git pull origin master --allow-unrelated-histories pulls the latest version of the master branch to the local
write code, modify code
git add. Add all files to the temporary storage area
git commit -m "message"
How to write information: Which file has been operated on and what needs to be paid attention to
Or one command to complete: git commit -a -m "information" Add to the temporary storage area and submit to the warehouse
git push origin master pushes the local warehouse to the remote warehouse
Enter your git email and password
If you think it is troublesome to enter the git account number and password every time, set the password to save it. For example, save the account password for 30 minutes
git config --global credential.helper 'cache --timeout=1800'
Pay attention to the problem
If you create a new remote warehouse with only the README.md file in it, and you want to push the code to the remote warehouse in the local warehouse, the above error will be reported, because the remote warehouse contains files that do not exist in the local warehouse, and the push may fail. Overwrite the files in the remote warehouse. Solution:
1. Synchronize the files on git/github to the local, change and merge the contents locally before uploading, and execute the following commands in sequence:
git pull origin master --allow-unrelated-histories pulls files and merges them locally
If the local warehouse is not cloned and there are files, an error will be reported, and parameters need to be added: git pull origin master --allow-unrelated-histories
git push origin master push
2. Forcibly push (not recommended)
git push -u origin +master
Forcibly uploading will overwrite the files in the remote warehouse, and it is not a last resort
If the code in the remote warehouse has been modified by others and you did not pull the latest version before modifying the local code, the code version will be different, and the submission will fail at this time. Yes, this will force the local code to overwrite the remote warehouse code (it will be overwritten git push --force origin 分支名
) Drop other people's modifications), so it is best to pull before changing the code every time. If there is no such branch in the remote, a new one will be created in the remote warehouse. It is not recommended to forcibly overwrite, if you want to forcibly overwrite, first ask someone in your team.
Backtracking operation: If you pull the code and find that your code has been misoperated by others, you can git reset --hard HEAD^
roll back the current branch of the local warehouse to the state of the last submission, and remember to switch to the corresponding branch before rolling back. It HEAD^^
represents the state of the last time, HEAD~100
and represents the state of the last 100 times. You can also replace HEAD with the serial number of the commit in the log in the previous step.
If there is a major change in the code, remember to push a version tag to facilitate version maintenance
git tag <name> create tag v1.0
git push origin <name> Push tags to remote warehouse
debugging:
To be continued...
Download open source code Note:
First check how many branches there are
git clone https://... 只会克隆 默认分支
To clone all branches, use the following command
git clone --mirror https://...
or:
git pull --all https://...
github speedup:
Github access in China is very slow, sometimes cloning a project fails, git clone acceleration method
1. Before executing git clone, execute the command:
git config --global url."https://ghproxy.com/".insteadOf https://
Add a replacement setting to the git global environment, which will automatically add the accelerated link of ghproxy.com to the front of the github link, so as to achieve the goal of quickly cloning the project.
The second method configuration file method (recommended)
can be accelerated by adding the following configuration in ~/.git/config, git access to Github
……前面的七七八八内容不用管
[url "https://ghproxy.com/https://github.com/"]
insteadOf = https://github.com/
Introduction to Git - Liao Xuefeng's official website (liaoxuefeng.com)