Git common command quick reference manual [produced by man san dao sauce]
2022-01-27 01:30:37 【Mansandao sauce】
In your daily development , There will be many Git The operation of , But you've never done , This article is a Book Git Command quick reference manual , It summarizes the most commonly used in my work in recent years Git usage . I believe it is helpful for daily development .
Most of the following common methods and commands only involve using , It doesn't involve the principle explanation . If in doubt , Please leave a message ~
List of articles
- General function
- Git Commit Statute
- git Ignore managed files and folders
- How to use specific SSH Key Submit GIT
- Git overall situation username And current project username
- Global Config and Warehouse Config
- Modify the submitted author information
- Git hit tag Tag Push to remote warehouse
- Windows Unable to create file name
- clone Failure to deal with （ Cannot create special file name ）
- modify remote Warehouse url
- An existing local project is associated with a new project Git Warehouse
- Compress commit
- Will be a lot commit Compress to a few
- Forcibly replace local with remote
- modify commit notes
- submodule Change the warehouse url
- Fallback related functions
- Branch related functions
- Git Switch local branches
- Merge dev to master Branch
- View the correspondence between remote branches associated with local branches
- One line of code directly pulls down the remote dev Branch
- To create local dev Branch and associate with remote dev Branch
- To create local dev Branch and create a new remote branch
- Delete the branch （ Local 、 long-range ）
feat： new function （feature） fix： repair bug docs： file （documentation） style： Format （ Changes that do not affect code operation ） refactor： restructure （ It's not new , It's not a revision bug Code changes ） test： Add tests chore： Changes in the build process or AIDS
Only later git already tracking There are some files you want to ignore , At this time, only adding the folder you want to ignore in the file will not take effect . Can be interpreted as With cache , We need to delete it manually tracking The file of , Execute the following command ：
git rm -r --cached ignoreFile（ignoreFile Is the file you want to ignore ）, Give Way git No longer tracking These documents .
Study git When , Before we started using it, we all configured a global user name and mailbox
git config --global user.name "github's Name" git config --global user.email "[email protected]" git config --list
If your company's project is self built gitlab above , If you don't configure the user name and email , The global , This time is wrong , The right approach is to target the company's projects , Configure it separately under the root directory of the project
git config user.name "xxxxxxx" git config user.email "[email protected]" git config --list
View the current configuration , The configuration viewed under the current project is the global configuration + Configuration of the current project , The configuration of the current project will be used first
Do not modify on the machine used together Global config, Can cause commit It's all your name .
Please use folder config （–local）,git Priority will be given to detecting folders config And look for global config
The answers given online are all scripts written by themselves , A little too cumbersome , Walking around segmentfault1 Found the answer :
First find the modification commit Previous , perform
git rebase -i commit id
git It will automatically call the configured editor to open an interface
Modify the first row of data ( It's the one we expect to modify commit) Of pick by edit
Then we can go through git commit --amend To modify user information freely , The operation is as follows ：
git commit --amend --author="xxx <[email protected]>" --no-edit
Continue to complete rebase,
git rebase --continue
git tag v1.0
In order to synchronize tags to remote servers , We can do that ：
By default ,git push It doesn't mean that tag Transfer the tag to the remote server , Tags can only be shared to remote warehouses through explicit commands .
1.push Single tag, The command format is ：
git push origin [tagname]
for example ：
git push origin v1.0 # Will local v1.0 Of tag Push to remote server
2.push all tag, The command format is ：
git push [origin] --tags for example ：git push --tags or git push origin --tags
As far as understand, you have the following options:
- ask project author to rename the file/directory in question or do it yourself
- try using git from a cygwin/msys2 build. The msys2 wrapper handles some Windows path issues, transforming them into legal ones, though I don’t know if it handles this issue.
- fix git for windows - take into use the UNC path. The maintainer said he would consider taking such patch.
- if you don’t really need to work on the file or directory, you could exclude it from checkout using sparse checkout.
git statusgit checkout -f HEAD
git remote set-url origin [url]
- First Rebase：
git rebase -i fb6ae281bad35fb70f15b93c22ef5ccf50ced238
- modify commit notes
- Strong push
git push -f
Sometimes the same branch , Both remote and local have been modified beyond recognition , If you want to replace local with remote , Use the following command
git fetch --all git reset --hard origin/master ( here master To change to the corresponding branch name ) git pull
git commit --amend
Method 1 ：
git clone --recursive xxxxx
Method 2 ：
git submodule init git submodule update
You should just be able to edit the .gitmodules file to update the URL and then run git submodule sync --recursive to reflect that change to the superproject and your working copy.
Then you need to go to the .git/modules/path_to_submodule dir and change its config file to update git path.
If repo history is different then you need to checkout new branch manually:
git submodule sync --recursive cd <submodule_dir> git fetch git checkout origin/master git branch master -f git checkout master
git reset --soft HEAD^
So you've successfully withdrawn your commit
Be careful , Just to withdraw commit operation , The code you wrote remains .
HEAD^ It means the last version , Or you could write it as HEAD~1
If you do 2 Time commit, I want to withdraw , have access to HEAD~2
As for these parameters ：
–mixed（ Default ）
intend ： Don't delete workspace change code , revoke commit, And cancel git add . operation
This is the default parameter ,git reset --mixed HEAD^ and git reset HEAD^ The effect is the same .
Don't delete workspace change code , revoke commit, No cancellation git add .
Delete workspace change code , revoke commit, revoke git add .
Note that after this operation , It's back to the last time commit state .
git reset --hard a7e1d279 git push -f origin master
After the local branch is rolled back , The version will lag behind the remote branch , The remote branch must be overwritten with forced push , Otherwise, it cannot be pushed to the remote branch
Git Meeting time gc, Clean up reflog, So don't wait too long to recover after being covered .
Back up the data in the current workspace
git reflog/git log -g
Show all historical operations , Find the submission you need （ Including those that have been deleted commit Record ,git log You can't view the deleted commit Record ）
2.1 Force back to what was deleted at that time commit
git reset --hard <SHA1>
2.2 Or directly
git cherry-pick <SHA1>
Just bring back the work of that version . But if there's a conflict, you have to deal with it .
3. Push the remote branch
git push -f origin <branch>
If it causes commit The reason for the loss is not recorded in reflog in , Like running
rm -Rf .git/logs/, because reflog The data is stored in .git/logs/ In the catalog , So there's no reflog 了 .
have access to
git fsck Tools , The tool checks the data integrity of the warehouse . If specified --full Options , This command shows all objects that are not referenced by other objects ( Point to ) All objects of .
then , It can be restored in the same way , That is to create a point to the SHA The branch of .
git checkout my-test
First switch to master On the branch
git checkout master
If it's multi person development It needs to be remotely master The code on pull Come down
git pull origin master
If it is a development of their own, there is no need , For the insurance period or pull
And then we put dev The code of the branch is merged into master On
git merge dev
Again ,dev Pull master Branch
equally , stay dev Branch use
git merge master
git branch -vv
git checkout -b Local branch name x origin/ Remote branch name x
Suppose the current branch is master, The branch to be created is my-test
git checkout -b my-test // Create... Under the current branch my-test Local branch of git branch --set-upstream-to=origin/my-test // Take the local branch my-test Associate to remote branch my-test On git branch -a // View remote branches
At this point, the remote branch my-test It's already created , And the local branch has been associated with the remote branch
Local push The code will push To the associated remote branch .
git checkout -b my-test git push origin my-test:my-testgit branch --set-upstream-to=origin/my-test
Delete local branch ：git branch -d Branch name （remotes/origin/ Branch name ）
Force local deletion ：git branch -D Branch name
Delete remote branch ：git push origin --delete Branch name
author[Mansandao sauce],Please bring the original link to reprint, thank you.
The sidebar is recommended
- Spring IOC container loading process
- [thinking] the difference between singleton mode and static method - object-oriented programming
- Hadoop environment setup (MySQL environment configuration)
- 10 minutes, using node JS creates a real-time early warning system for bad weather!
- Git tool
- Force deduction algorithm - 92 Reverse linked list II
- What is the sub problem of dynamic programming?
- C / C + +: static keyword summary
- Idea does not have the artifacts option when configuring Tomcat
- Anaconda can't open it
guess what you like
I don't know how to start this
Matlab simulation of transportation optimization algorithm based on PSO
MySQL slow log optimization
[Vue] as the window is stretched (larger, smaller, wider and higher), the text will not be displayed
Popular Linux distributions for embedded computing
Suzhou computer research
After installing SSL Certificate in Windows + tomcat, the domain name request is not successful. Please answer!!
Implementation time output and greetings of jQuery instance
The 72 year old uncle became popular. Wu Jing and Guo fan made his story into a film, which made countless dreamers blush
How to save computer research
- Springboot implements excel import and export, which is easy to use, and poi can be thrown away
- The final examination subjects of a class are mathematical programming, and the scores are sorted and output from high to low
- Two pronged approach, Tsinghua Professor Pro code JDK and hotspot source code notes, one-time learning to understand
- C + + recursive knapsack problem
- The use of GIT and GitHub and the latest git tutorial are easy to understand -- Video notes of crazy God speaking
- PostgreSQL statement query
- Ignition database test
- Context didn't understand why he got a high salary?, Nginxfair principle
- Bootstrap switch switch control user's guide, springcloud actual combat video
- A list that contains only strings. What other search methods can be used except sequential search
- [matlab path planning] multi ant colony algorithm grid map path planning [including GUI source code 650]
- [matlab path planning] improved genetic algorithm grid map path planning [including source code phase 525]
- Iinternet network path management system
- Appium settings app is not running after 5000ms
- Reactnative foundation - 07 (background image, status bar, statusbar)
- Reactnative foundation - 04 (custom rpx)
- If you want an embedded database (H2, hsql or Derby), please put it on the classpath
- When using stm32g070 Hal library, if you want to write to flash, you must perform an erase. If you don't let it, you can't write continuously.
- Linux checks where the software is installed and what files are installed
- SQL statement fuzzy query and time interval filtering
- 69. Sqrt (x) (c + + problem solving version with vs runnable source program)
- Fresh students are about to graduate. Do you choose Java development or big data?
- Java project: OA management system (java + SSM + bootstrap + MySQL + JSP)
- Titanic passenger survival prediction
- Vectorization of deep learning formula
- Configuration and use of private image warehouse of microservice architect docker
- For someone, delete return 1 and return 0
- How does Java dynamically obtain what type of data is passed? It is used to judge whether the data is the same, dynamic data type
- How does the database cow optimize SQL?
- [data structure] chain structure of binary tree (pre order traversal) (middle order traversal) (post order traversal) (sequence traversal)
- Webpack packaging optimization solution
- 5. Operation element
- Detailed explanation of red and black trees
- redhat7. 9 install database 19C
- Blue Bridge Cup notes: (the given elements are not repeated) complete arrangement (arrangement cannot be repeated, arrangement can be repeated)
- Detailed explanation of springboot default package scanning mechanism and @ componentscan specified scanning path
- How to solve the run-time exception of test times
- Detailed explanation of k8s management tool kubectl
- Android system view memory command