Common git commands

Source: Internet
Author: User
Tags git commands
Git official documentationGraphical tool gitk

1. Git Basic settings $ git config --global user.name "Your Name"
$ git config --global user.email "[email protected]"
$ Git config -- List View configuration records
You can also enter the working root directory and run git config-E, which will only be valid for this workspace.
Link 1 link 2

2. Common commands
Git init: create a local version Library
Git Add "test.txt" add the specified file to the version Library

Git Add. Add all files to the version Library
git clean -fClear Untracked files
git commit -m "wrote a test file" Submit the modified file to the repository. The-M parameter is used to set the comments for this submission. git commit -a -m "wrote a test file" If multiple files need to be submitted, you must use the-a parameter.

Git status: Check the current status of the Repository. It shows the files that have been modified and those files need to be submitted.

Git log view other parameters of version submission records
Git log -- stat view brief statistics on the number of rows to be added and changed for the Submission record
Git log -- pretty = oneline only displays the commit ID (version number) and comments of the submission record git log --pretty=oneline --abbrev-commit

Git reset -- hard head ^ roll back the current version to the previous version
git reset --hard HEAD~100    
Git reset -- hard commit_id: roll back to the specified version number

Git reflog view Command Execution records Git diff head -- view the differences between the latest version in the workspace and version library for file names

Git checkout -- readme.txt undo all the modifications to the file in the workspace and roll back to the latest version in the version library or temporary storage zone.
Git reset head readme.txt: roll back the changes in the temporary storage area to the Work Area

Git RM readme.txt delete files from the version Library
git show A hash file submitted View the modification record of a file

git remote add origin [email protected]:username/learngit.gitAssociate the local git library with the remote database. The origin is the name of the remote database (which can be defined as needed)

Git push-u origin master pushes all the content of the master branch in the local database to the remote database. The-u parameter is used to associate the local database with the remote database. This parameter is not required for normal submission.

Ssh-keygen-t rsa-c "[email protected]" creates an SSH key. Each client creates a key. GitHub can accurately identify the submitter when submitting the key.


View history:

View submission history (all): $ git log
View the submission history and display the Statistics: $ git log -- stat
View the submission history and view the difference: $ git log-P
View the last two submission history and view the difference: $ git log-P-2
View the submission history in the last two weeks: $ git log -- since = 2. Weeks
View the submission history after a certain time point: $ git log -- since = "2008-09-14"
View the submission history before a certain time point: $ git log -- until = "2008-09-14"
View the submission history of an author: $ git log -- author = "stupid"

View the submission history and display it in a single row: $ git log -- pretty = oneline

View the submission history and display the format: $ git log -- pretty = format: "% H-% an, % AR: % s"

% H complete hash string of the submitted object (COMMIT)
% H submit the brief hash string of the object
% T full hash string of the tree object
Brief hash string of the % t tree object
% P full hash string of the parent object (parent)
% P brief hash string of the parent object
% An author (author) Name

% Ar author revision date, displayed in the previous manner
% CN submitter name
% Cr submission date, displayed in the previous manner
% S submission instructions

[Log parameters]

-P displays the differences between each update in patch format.
-- Stat: displays the statistics of each update of a file.
-- Distinct stat only displays the last row modification in -- stat to add and remove statistics.
-- Name-only displays the modified file list only after the information is submitted.
-- Name-status: displays the list of newly added, modified, and deleted files.
-- Abbrev-commit only displays the first few characters of SHA-1, not all 40 characters.
-- Relative-date is displayed with a relatively short relative time (for example, "2 weeks ago ").
-- Graph displays the branch merge history in ASCII format.
-- Pretty displays Historical submission information in other formats. Available options include oneline, short, full, Fuller, and format (followed by the specified format ).


Schematic diagram of workspace, version library, and temporary storage Zone
Branch
Git checkout-B Dev: Create and switch to Dev Branch Switch git checkout master to master Branch
Git branch: view all current branches. A * sign is marked before the current branch.
Git branch Dev create Dev Branch
git merge dev Merge Dev branches to master branches
Git merge -- no-FF-M "comment content" Dev generates a new commit When merging Dev branches. The branch information can be seen from the branch history.
Note that-- No-FFParameter, indicating to disable "Fast Forward" Git branch-D Dev Delete Dev Branch


Tag
Switch git tag V1.0 to the branch to be tagged and create the V1.0 tag.

Git tag to view all tags
Git tag v0.9 commit_id tag the version number
Git show v0.9 view Tag Information
Git tag-A v0.1-M "version 0.1 released"commit_idUse-a to specify the label name and-M to specify the description text.
Git tag-D v0.1 Delete tag
Git push origin V1.0 pushes tags to a remote database
Git push Origin -- tags one-time push all the local tags that have not been pushed to a remote device


Delete unsubmitted local changes
Submitted to the temporary storage zone:

Git reset -- hard cancels cached content

Git clean-xdf deletes all files not submitted to the temporary storage zone from the disk


Not submitted to the temporary storage zone:

Git checkout. Undo All workspace file modifications Git checkout filename undo the specified workspace FileModification

Git checkout *. Java unmodifies all java files in the Workspace
git clean -xdf

Common git commands

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.