Summary of Git Centralized Operating Commands in Linux

Time:2019-8-20

SyntaxHighlighter

Git version # View version
Git config-l# View the current configuration
Git config -- global user. name "Dean"  Set user name, mailbox 
Git config -- global user.email [email protected] Set user name and mailbox 
Git config -- global alias. CI commit # Sets the alias of the GIT command
Git config -- global alias. co checkout # Sets the alias of the GIT command

Git repository:

# Create a local git repository and name it: 
git init demo
# Clone a remote git repository to the specified path: 
git clone https://github.com/a396901990/android.git /path/workpsace

Git branch:

Git branch # view branch
Git remote show origin # view all branches
Git branch < branchname > # create new branch
Git checkout < branchname > # switch to branch
Git checkout-b < new_branch > # Create and switch to a new branch
Git branch-d < branchname > # delete branch (-D delete) 
Git branch-m < old > < New > # rename of local branch

Git add:

Git add < File > # adds files with locally specified file names or directories (new and modified, not deleted) to the temporary area
Git add. # Add all local (new and modified, not deleted) files to the temporary area
Git add-u # adds local (modified and deleted, no new) files to the temporary area
Git add-A# adds all local changes to the temporary area (git add-A = git add. +git add-u)
Git add-i  Open an interactive interface to add files as needed

Git deletion/renaming (rm/mv):

Git RM < File > # Delete files
Git rm-r <floder> #Delete folders
Git RM -- cached < File > # deletes files from the version library, but does not delete files   
Git MV < old_name > < new_name >  file renaming

Git commit:

Git commit-m "comment" # submit the contents in the temporary area (added) and add comments
Git commit - a # adds the modified file to the temporary area (excluding untracked files) and submits it.
Git commit -- amend # modify commit submitted (no push)
Git commit -- amend-m "comment" # modify commit annotations

Git difference (diff):

Git diff # View differences in working tree temporary area (index)
Git diff -- cached # View the difference between a temporary file (stage) and an uncommitted file (commit)
Git diff -- stage D # Ibid.
Git diff HEAD # View the difference after the last commit (HEAD represents the last commit information)
Git diff -- stat # View Shows Brief Results (File List)
Git diff commit1 commit2 # compares two submissions (also branch, hash value)

Git View History (log):

git log
Git log-3 # View the first three changes
Git log -- one line # shows a log
Git log - P # View details of modifications 
Git log -- stat # View submission statistics
Git log -- graph # shows when branching and merging occur

Git view status:

Git status # View the status of your code in the cache with the current working directory
Git status-s # outputs the results in a short form
Git status -- ignore # displays ignored files

Git storage (stash):

Git stash # Save the current progress
Git stash save "message" # save progress with instructions
Git stash list # Displays progress list
Git stash pop # restores the latest saved work progress and deletes the restored work progress from the stored list
Git stash apply # restores the latest save progress, but does not delete
Git stash drop # Deletes a progress, defaults to delete the latest
Git stash clear # delete all

Git reset:

Git reset -- mixed # resets the temporary area as git reset without any parameters, but does not change the workspace
Git reset -- soft # falls back to a version without changing the temporary and workspace (commit directly if you have to commit)
Git reset -- hard # completely falls back to a version, replacing the temporary and workspace, and the local source code becomes the content of the previous version.

Git reset # evacuates the contents previously added to the temporary area with the GIT add command (equivalent to the reverse operation of GIT add-A)
Git reset HEAD # HEAD works the same as above, because reference reset to HEAD is equivalent to no reset
Git reset filename # evacuates the file from the temporary area (equivalent to the reverse operation of GIT add filename)
Git reset HEAD ^# Reference fallback once (workspace unchanged, temporary area fallback)
Git reset -- soft HEAD~3 # reference fallback three times (workspace unchanged, temporary area unchanged)

Git revocation (revert):

Git revert commit # Undo specified commit
Git revert HEAD # Undo the last commit
Git revert-no-edit HEAD # Undo the last time and use the default annotation directly
Git revert-n HEAD # Undo Last Time but Not Commit

Git Selection (cherry-pick):

Git cherry-pick < commit_id > # for applying commit modifications of another local branch to the current branch

Git merge:

Git merge < branch_name >  merge
Git merge -- no-ff < branch_name > # adopts no fast forward merging method, which generates a new commit at the same time of merging
Git merge -- abort # try to go back to the state before merge (may fail)
Git merge -- squash < branch_name > # merges the target branches without commit information. After execution, you need to submit a commit (benefits, clean code)

Git rebase:

git rebase <branch_name>  # 
Git rebase -- continue # after executing rebase to resolve conflicts, executing this command will continue to apply the remaining patches
Git rebase -- skip # skips the current submission
Git rebase -- abort # terminates rebase, and the branch returns to its pre-rebase state

Git fetch / pull:

Git fetch Gets the latest version from remote to local, and does not automatically merge

Git pull # Get the latest version remotely and merge locally
Git pull -- rebase # temporarily saves local changes, merges remote latest changes, and merges local changes that have just been temporarily saved (without generating useless merge synchronization)

Git push:

Git push origin master # pushes the local branch to the master branch of the origin host
Git push-u origin master u specifies origin as the default host, and then git push can be used without any parameters.
Git push-f origin f push, which produces a "non-fast-forward merge" on the remote host
Git push -- all origin # pushes all local branches to the origin master

Commands for Git centralized operations:

1) Relevant commands of remote warehouse
Check-out warehouse: $git clone git://github.com/jquery/jquery.git
View remote warehouse: $git remote-v
Add remote warehouse: $git remote add [name] [url]
Delete remote warehouse: $git remote RM [name]
Modify remote warehouse: $git remote set-url — push [name] [newUrl]
Draw remote warehouse: $git pull [remoteName] [local BranchName]
Push remote warehouse: $git push [remoteName] [local BranchName]
* If you want to submit a local branch test to a remote warehouse as the master branch of the remote warehouse, or as another branch called test, the following:
Git push origin test: master // submit local test branch as remote master branch
Git push origin test: test // Submit local test branch as remote test branch

2) branch operation related commands
View local branches: $git branch
View remote branches: $git branch-r
Create a local branch: $git branch [name] – Note that the new branch will not automatically switch to the current branch after it is created
Switching branches: $git checkout [name]
Create a new branch and switch to it immediately: $git checkout-b [name]
Delete branches: $git branch – D [name] – — D option can only delete branches that have participated in the merge, but cannot delete branches that have not been merged. If you want to force a branch to be deleted, you can use the – D option
Merge Branches: $git merge [name] – Merge Branches named [name] with Current Branches
Create a remote branch (local branch push to remote): $git push origin [name]
Delete remote branches: $git push origin: heads /[name] or $git push origin: [name]
* Create empty branches: (remember to submit changes to your current branch before executing the command, otherwise it will be forced to delete without regret)
$git symbolic-ref HEAD refs/heads/[name]
$rm .git/index
$git clean -fdx

3) Version (tag) operation related commands
View version: $git tag
Create version: $git tag [name]
Deleted version: $git tag-d [name]
View the remote version: $git tag-r
Create a remote version (local version push to remote): $git push origin [name]
Delete remote version: $git push origin: refs/tags/[name]
Merge tags from remote warehouses to local: $git pull origin — Tags
Upload local tags to remote warehouses: $git push origin — Tags
Create annotated tag: $git tag – a [name] – M’yourMessage’

4) Submodule related operation commands
Add submodules: $git submodule add [url] [path]
For example: $git submodule add git://github.com/soberh/ui-libs.git src/main/webapp/ui-libs
Initialization sub-module: $git submodule init — run only once when the warehouse is first checked out
Update submodule: $git submodule update — run every time you update or switch branches

Delete the sub-module: (4 steps)
1) $ git rm –cached [path]
2) Edit the’.gitmodules’file and delete the relevant configuration nodes of the sub-module.
3) Edit the’.git/config’file and delete the relevant configuration nodes of the sub-module.
4) Manual deletion of directories remaining in sub-modules
5) Ignore some files and folders that are not submitted

Create a file named “. gitignore” in the warehouse root directory and write to unnecessary folder names or files. Each element takes up one line, such as
target
bin
*.db

Common Git commands

Git branch Views All Local Branches
Git status view current status
Git commit submission
Git branch – a Views all branches
Git branch – r to view all local branches
Git commit-am “init” submitted and annotated
git remote add origin [email protected]:ndshow
Git push origin master pushes files to the server
Git remote show origin displays resources in remote library origin
git push origin master:develop
Git push origin master: hb-dev associates local libraries with libraries on the server
Git checkout — track origin/dev switch to remote dev branch
Git branch-D master development deletes local library development
Git checkout-b dev creates a new local branch dev
Git merge origin / dev merges branch dev with current branch
Git checkout dev switch to local dev branch
Git remote show view remote library
git add .
Git RM File Name (including Path) Deletes the specified file from Git
Git clone git://github.com/schacon/grit.git pulls the code down from the server
Git config — list to see all users
Git ls-files to see what has been submitted
Git RM [file name] deletes a file
Git commit-a submits all changes to the current repos
Git add [file name] add a file to git index
Git commit-v You can see commit differences when you use the-v parameter
Git commit-m “This is the message describing the commit” to add commit information
Git commit-a-a is for add, add all changes to git index and commit it again
Git commit-a-v general submission order
Look at your commit log in Git log
Git diff to view updates that have not yet been temporarily saved
Git RM A.A Remove Files (Deleted from Temporary and Workspace)
Git RM — cached A.A removes files (only from the temporary area)
Git commit-m “remove” removes files (delete from Git)
Git rm-f A.A Forced Removal of Modified Files (Deleted from Temporary and Workspace)
Git diff — cached or $git diff — stage to view uncommitted updates
Git stash push gives the file to push into a temporary space
Git stash pop pops files from temporary space
———————————————————
git remote add origin [email protected]:username/Hello-World.git
Git push origin master submits the local project to the server
———————————————————–
Git pull local and server-side synchronization
—————————————————————–
The git push (remote warehouse name) pushes the local branch to the server.
git push origin serverfix:awesomebranch
——————————————————————
Git fetch is equivalent to remotely retrieving the latest version to the local, not automatically merge
Git commit-a-m “log_message” (-a is to submit all changes, and-m is to add log information) local changes are synchronized to the server side:
Git branch_0.1 master creates branch_0.1 branch from main branch master
Git branch-m branch_0.1 branch_1.0 renames branch_0.1 to branch_1.0
Git checkout branch_1.0/master switch to branch_1.0/master branch
du -hs

———————————————————–
mkdir WebApp
cd WebApp
git init
touch README
git add README
git commit -m ‘first commit’
git remote add origin [email protected]:daixu/WebApp.git
git push -u origin master
Common Git Command Chart