Git commonly used commands

Git commonly used commands

OMMP code submission process
0. Configuration:
git config --list View current configuration
git congig --global user.name user
This will display your name submitted to git
format: git config [–local|–global|–system] –unset section.key
format: git config [–local|–global|–system] -l
to view warehouse-level config, command: git config –local -l
to view global level config, command: git config –global -l
to view System-level config, command: git config –system -l
to view the currently effective configuration, command: git config -l, this time will display the configuration information calculated by the final three configuration files

git config --global uesr.name 张三00111111
git config --global user.email "[email protected]"

Configuration key:

cd ~/.ssh
ssh-keygen -t rsa -C “aaa@164.com.cn

The generated public key is given to the git tool, not detailed here
1. Pull the latest code

git pull

2. Modify the code
Confirm the modified file
git status
3. Submit the modified code to the temporary storage area

git add .
git restore --staged . 

4. Submit to the remote warehouse

 git commit -m '提交内容注解'

rollback:

git reset
git reset --soft HEAD^
^也可以~数字表示
HEAD~0 表示当前版本
HEAD~1 上一个版本
HEAD^2 上上一个版本
HEAD^3 上上上一个版本

5. Submit the code

git push origin HEAD:refs/for/master

origin HEAD: refs/for/master is the meaning of the main branch, or you can leave it blank, and the default is 6. If
there is no changId,
execute git log to check whether there is a character like "Change-Id:" in your commit,
if not, Execute in the root directory of the current code:

scp -p -P 29418 aaa@163.com.cn:hooks/commit-msg  .git/hooks/

Then git commit --amend without modifying anything, save and exit.
At this time, you can see the Change Id in the git log
7. Delete untracked files

git clean [-d] [-f] [-i] [-n] [-q] [-e ] [-x | -X] [--] 

-d deletes the untracked directory and the files under the directory. If the directory contains other git warehouse files, it will not be deleted (-dff can be deleted).
-f If clean.requireForce under git cofig is true, then the clean operation requires -f (–force) to enforce.
-i Enter the interactive mode
-n to view the files to be deleted, and not actually delete the files
8. Hide the recovery modification code

git stash隐藏修改的代码
git stash pop隐藏的文本修复

git stash #Store all uncommitted changes in stash. Reply with git stash pop.
9. Compare the difference between the current code and the modified file of the last code
git diff --name-only HEAD~ HEAD > changes.txt
10. Abandon local modification and force update

git fetch --all
git reset --hard OMM

11. Obtain the complete commit id (eg: bb4f92a7d4cbafb67d259edea5a1fa2dd6b4cc7a)

git rev-parse HEAD

Get short commit id (eg: bb4f92a)

git rev-parse --short HEAD

Get the latest branch that has been submitted but not merged
shortCommit=$(git ls-remote | awk '{print $2}' | sed 's/// /g' | sort -n -k4 | tail -n 1 | sed 's/ ///g')
git pull "Ssh connection of the code" ${shortCommit}
12. Roll back the version
and confirm the time point

git log --oneline --before '12-23-2020'

view id

git reset --hard id

Git fetch is to pull the latest content of the remote host to the local, and the user decides whether to merge it into the working local branch after checking it.
other:

git show --pretty=format: --name-only $GERRIT_PATCHSET_REVISION>codealldiff;
git show --diff-filter=d --pretty=format: --name-only $GERRIT_PATCHSET_REVISION>codediff;
git show --diff-filter=cdmr --pretty=format: --name-only $GERRIT_PATCHSET_REVISION>codeadd;
git diff --name-only 

Guess you like

Origin blog.csdn.net/Artisan_w/article/details/132225616