I have been using Git for almost a year, and the command line is more and more used, so I summarize the common operations in my work here for better review and query.


Basic Git workflow of our company:

$ git co(checkout) -b developCreate the develop branch

$ git pushPush the current branch (develop) to the remote repository

------------ follow the small batch submission principle ------------

$ git st(status)# β†’ View the working status of the current branch workspace and staging area

$ git diff# β†’ diff file (⚠️ important important important)

$ git ci(commit)Β . # β†’ Commit this modification

------------ The above three steps are used most frequently -----------

$ git fetch --all# β†’ Pull all the latest remote code

$ git merge origin/developΒ  Β Merge colleague changes into the current branch (first person, second person)

$ git merge origin/masterMerge origin/master into the current branch before going online

$ git pushPush the current branch to the remote repository

$ git merge --no-ff origin/develop> > Merge origin/ Develop into the remote trunk origin/master

-------- divides -------- and cuts -------- line --------

πŸ‘‰ HEAD: Indicates the current COMMIT reference

$git version # β†’ git version

$git branch # β†’ check all local branches

$git branch -r # β†’ check all remote branches

$git branch -a # β†’ check all remote and local branches

$git branch -d

# β†’ delete branchname

$git branch -m brancholdname branchnewName # β†’ rename branch

$git branch

# β†’ create branchname

$git checkout

#

$git checkout -b

# β†’ $git checkout -b

# β†’

$git checkout — xx/xx #

$git pull origin: $git pull origin: $git pull origin: $git pull origin: $git pull origin: $git pull origin: $git pull origin: $git pull origin: $git pull origin: $git pull origin: $git pull origin: $git pull origin: $git pull origin

$ git pull origin master --allow-unrelated-historiesAllow to merge the history of two different projects

$git push origin -d

$ git fetch --p

Update the branch

$git status # β†’ check the status of local workspaces and temporary files

$git add xx # β†’ add xx file to the temporary store

$git commit -m ‘ ‘# β†’ $git commit -m

$git commit -am(-a -m) # β†’ commit all changes

$Β git commit ./xxGit add./xx + git commit

When you commit with vi, you will see the current branch and the files that you changed during the commit. If you find the commit wrong, you can undo the commit in time (of course, you can undo the commit after the commit, but it is a little more complicated)

$git commit –amend # β†’ merge the staging area with the current commit to create a new commit to replace the current commit

$git stash # β†’ Hide the current work and work on it later when the site is restored

$git stash pop # β†’ restore work site (restore hidden files and stash list)



$Β git fetch --all
# β†’ retrieve all updates from remote host to local

$git merge origin/master # β†’ merge remote branch on local branch

$git merge –no-ff origin/develop

$git merge –abort # β†’ Abort the merge and return to the state before the merge (πŸ‘)

$git pull origin master $git pull origin master

$ git fetch origin masterΒ + $ git merge origin/master
(The former is safer)

$git push origin # β†’ $git push origin # β†’ $git push

$git log xx # β†’ check the commit record of xx file

$Β git log -p xx
# β†’ check diff of xx file every time it is submitted

$git log –pretty=oneline xx # β†’ $git log

$Β git log --pretty=raw
Select * from 'root' where 'root' does not have a parent '

$git log –graph # β†’ see the tree generated by the current branch commit

$Β git diff HEAD HEAD^1 -- xx
Check the differences between different versions of xx file

$git diff HEAD~1 #

The difference between ‘~’ and ‘^’ in πŸ‘‰

(< commit > | HEAD) ^ n, father is the HEAD of the NTH submitted, can pass behind the "^" keep up with a number, which submitted a parent said, "^" fairly "^ 1". For example, HEAD^2 represents the second parent commit of HEAD. (< commit > | HEAD) ~ n, refers to the HEAD of the NTH ancestors to submit, can pass behind the "to" keep up with a number, which submitted a grandfather said, "and" pretty "~ 1", "~ n" is equivalent to a continuous < n > "^". For example, HEAD~2 indicates the first parent commit of the first parent commit of HEAD.

Equation 1: HEAD~ === HEAD^ === HEAD^1

HEAD~2 === HEAD^^ === HEAD^1^1

$git diff –staged/–cached

$git show –stat # β†’ check the last modification

$git show HEAD # β†’ check the change in the specified version

$git show HEAD XXX # β†’ git show HEAD XXX # β†’

$Β git reset --hard HEAD
# β†’ Roll back to the specified version while clearing all changes to the working directory

$git reset –soft HEAD # β†’ roll back to the specified version while keeping the contents of the working directory and the staging area, and put any new file differences caused by the reset location into the staging area (πŸ‘)

$git reset –mixed HEAD # β†’ (default) roll back to the specified version while keeping the contents of the working directory and clearing the temporary area (πŸ‘)

$git reset –hard origin/master

πŸ‘‰ –hard –soft –mixed

βœ’οΈ Assume that the current commit and working directory are as follows:Copy the code



1 ️ If you then execute:
git reset --hard HEAD^

All changes disappear except for untracked files ⬆️

Git show --stat check the current commit⬆️

2 ️ If you then execute:
git reset --soft HEAD^

Commit changes made before reset are put into the staging area and the working directory ⬆️ is kept

Git show --stat check the current commit⬆️

3 ️ If you then execute:git reset --mixed HEAD^As with --soft, the working directory is kept, but the staging area is all cleared and previous commit changes are placed in untracked files ⬆️

Git show --stat check the current commit⬆️


$git reflog show –date=iso

# β†’

$ git branch -r | awk ‘{print $1}’ | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk ‘{print $1}’ | xargs Git branch -d # β†’ delete local branch that has been deleted at remote



$git remote show origin # β†’ $git remote show origin #



$Β git remote prune origin
# β†’ delete branches where the remote repository does not exist === git fetch -p
$ Git remote add origin SSH ://[email protected]:10022/fe-dev.git# β†’ Associate the remote repository



$git config # β†’ check and edit git configuration

To view

Format:git config [--local|--global|--system] -l

$Β git config --local -l
# β†’ Check the repository level config

$Β git config --global -l
# β†’ View the global config



The editor

Format:git config [--local|--global|--system] -e

$Β git config --local -e
Β 
Edit the repository level config

$Β git config --global -e
Β 
Edit the global config



Modify the

Format:git config [--local|--global|--system] section.key value

$Β git config --local push.default 'simple'
Change the default behavior of the repository push. Default

$Β git config --global push.default 'current'
Change the default behavior of global push. Default



* About Git Default configuration here

increase

Format: git config [- local | – global | — system] — add section. The key value (the default is to add in the local configuration)

$Β git config --add cat.name songhw
Cat. Name = songhw

$Β git config --local --add cat.name songhw
# β†’ Is the same as the previous step

$Β git config --global --add cat.name lhammer
Cat. Name = lhammer



To obtain

Format: git config [- local | – global | — system] — get section. The key (default is to obtain the local content of the configuration)

$Β git config --get cat.name
# β†’ Output songhw

$Β git config --local --get cat.name
# β†’ Output results as in the previous step

$Β git config --global --get cat.name
Output lHAMMER



delete

Format:git config [--local|--global|--system] --unset section.key

$Β git config --local --unset cat.name
Β 
Select * from local where cat.name = songhw

$git config –global –unset cat.name # β†’ delete local configuration cat.name = lhammer



$Β git rebase master
# β†’ Rebase the master on the current branch

$git rebase – I commit #

Change the operation instruction for the commit to be modified from pick to EditCopy the code

$Β git
rebase --continue
After the modification, continue rebase

$gitrebase –onto HEAD HEAD^1

# β†’



$Β git push origin <brancename> -f
# β†’ Ignore conflicts and force submission

$git Revert HEAD # β†’ undo commit (πŸ‘)

πŸ‘‰ Git Revert and Git rebase –onto

Git Revert adds a new commit, which is the reverse of the commit, cancels each other out to create the undo effect. In the commit history, there are two commits, the original commit and the reverse commit. Git rebase –onto deletes the commit directly from the history.

$git reflog HEAD # β†’ git reflog HEAD #

$git checkout HEAD(c08de9a) # β†’ c08de9a brance

$Β git checkout -b <brancename>
# β†’ create <brancename> again to retrieve the deleted branch

Note: A commit that is no longer referred to directly or indirectly is reclaimed by Git at a certain time, so reflog a branch in time, otherwise it may be reclaimed forever

$Β git tag
</code> </code>

$git tag -l version1.* # β†’ only list 1. Several versions of

$Β Git tag < tagname > (version 1.0)
</code> </code>

$git tag -a

(version1.0) -m ‘first version’ # β†’ create
tag

$Β Git tag -d <tagname>(version 1.0)
</code> </code>

$git checkout

(version 1.0)



refs:

Β» lhammer ‘s gitconfig

Default git push and pull behavior

Β» git config – pushdefault

Git root — the difference between ^ and ~