1. Display the current configuration information
git config--list
2. Create Repo
Get it from somewhere else
git clone git://git.kernel.org/pub/scm/git/git.git
Build yourself
mkdir test
CD test
Git init
3. Display Status
git status
4. Commit
git add file.1 file.2 Add the file to index first. This commits to know which files to commit.
Or
Git add-p
Used to interactively choose which changes need to be commit
git commit-m "log Message"
Or
Git commit-a
Automatically check what files should be commit. If this is a new file, you still need to add it using git Add.
5. Show previous work
git log
Output format
git log
Git log-p
Show Patches
git log--stat
A summary of the display changes
git log--graph
Displays only the current branch
git log--graph--all
Show All Branch's
git log--graph--all--decorate
Show Branch's name
git log--pretty=oneline, short, full, fuller
The output has a different log format
git log--pretty=format: "%h-%an,%ar:%s"
Output in the specified format. For additional options on--pretty and the specific format format, refer to the section pretty format in git log--help.
git log--follow file.c
This feature is interesting, especially when FILE.C is moved.
Usually we move a file to a directory. If you do this, git log cannot display the records before the directory was moved.
Then add--follow.
Filter for git log
Git log-2-P displays log and diff for the last two commits
git log--author= "author Name" to filter the log for a specific author
git log--since= "2012-2-23"--before= "2012-2-24" Filter time period
git log--grep= "key word" to find the keyword in the commit message
git log branch--not master looks at the records on branch, but not on master.
Git log-s "Func_name" to find a character that appears, or move out of a commit. For example, you can find out when a function was added, or deleted.
Git show SHA1 This SHA1 is the SHA1 of each commit, which shows the full information of a commit, including the diff
6. Undo Changes
Git checkout--file.1
This change of FILE.1 was revoked. Just undo the change without staged.
The middle--it shows that this is a file, not a branch name.
git reset--hard HEAD
All non-commit changes were revoked, including the stage and no stage.
The result of this command is the same
git checkout HEAD file.1
Both staged and non-staged will be cleared.
Sometimes we find that we have a problem with a commit, don't want it, and want to get rid of it.
git revert HEAD automatically has to redo a commit and return the last commit.
git revert head^ automatically has to redo a commit and return the final second commit.
7. Delete a Commit
git reset--hard head~1
The most recent commit was deleted
8. Modify a recent Commit
git commit--amend
7. Display the changes you have made
Git diff
Show all the changes. There is no add to index.
git diff--staged or git diff--cached
Show staged changes, that is, add the east, that is going to commit the dongdong.
git diff commit1 Commit2
Shows the changes between the two commits, from Commit1 to Commit2.
git diff commit1..commit2
Two points, the effect is the same as above
git diff commit1...commit2
The three dots, which represent the changes that took place in the Commit2 branch, continued to commit1 and commit2 common fathers.
Git blame-c file1.c
Show file specific changes .... Well, it seems to be used to find out who's wrong?
Git blame-ln,m file1.c
See the changes in the N,m two rows.
git blame commit1~1-ln,m file1.c
See the changes before the commit1 version. Trace the previous log.
Git blame commit1~1-ln,m--old/file.c
If the file has been renamed or moved, enter the name of the old file.
And be sure to add--, sure.
8. Delete a file
git rm file-name
Delete this file from the library and the current working directory
git rm--cached File-name
Delete only from the library, preserving the current local file.
9. Renaming a file
git mv file file-new
10. Apply Patches
git apply Patch-file
Do this by applying the patch from the Patch-file. The effect is similar to the patch command.
But the advantage is that git apply either succeeds or is unsuccessful. Do not want patch, there may be a part of the patch hit, but some did not hit.
After git apply, it does not automatically generate a commit.
git apply--check can be used to detect whether this patch will cause a conflict or failure.
git am patch-file
This is a command specifically designed for Git. Patch-file is generated by Git format-patch.
It contains author information and a simple description.
After Git am, a commit is automatically generated.
git am--resolved
There may be conflict in the Git AM process. If you encounter conflict, then you need to manually modify code, git add
Using Git am--resolved
11 Delete some files that do not have git add;
Git clean
Parameters
-N Show files and directories to be deleted
-F Delete File
-DF Deleting files and directories
Git clean-df alps/
Git remote
Git is a distributed code management tool, so you can support multiple warehouses, and in Git, the repositories on the server are called remotes locally.
Direct Clone a repository:
$: Git clone [email protected]:p Rojects/search.git
Another way to clone:
# Create a directory to initialize the local repository
$: mkdir Search && CD Search
$: Git init
# Add a remote warehouse path
$: Git remote add github [email protected]:yyfrankyy/search.git
# Actually, pull is the Fetch + merge
$: Git pull GitHub--all--tags
Migrating your working directory to GitHub:
$: Git remote add github [email protected]:yyfrankyy/search.git
$: git push GitHub--all--tags
Show All remote repositories
$: Git remote-v
Origin [email protected]:p rojects/search.git (FETCH)
Origin [email protected]:p rojects/search.git (push)
GitHub [email protected]:yyfrankyy/search.git (FETCH)
GitHub [email protected]:yyfrankyy/search.git (push)
Renaming a remote repository
$: Git remote rename github gh
$: Git remote
Origin
Gh
Delete a remote repository
$: Git remote RM github
$: Git remote
Origin
Fetch data from the remote repository and update the local repository:
$: Git fetch origin
Remote:counting objects:58, done.
Remote:compressing objects:100% (41/41), done.
Remote:total (Delta), reused 1 (Delta 0)
Unpacking objects:100% (44/44), done.
From Git://search.ued.taobao.net:projects/search.git
* [New branch] product--origin/product
View remote warehouse information that can be used to track someone else's push:
$: Git remote show origin
* Remote origin
Fetch URL: [email protected]:p rojects/search.git
push URL: [Email protected]:p rojects/search.git
HEAD branch:master
Remote branches:
master tracked
p4popt tracked
prepub tracked
Product tracked
Local branches configured for ' git pull ':
Master Merges with remote master
p4popt merges with remote p4popt
prepub merges with remote prepub
product merges with remote product
Local refs confi gured for ' git push ':
master pushes to master (up to date)
p4popt pushes to p4popt (up to date)
prepub pushes to prepub (up to date)
; product pushes to product (up to date)
Git operations Command collation under Linux system