1. Configuration
git config--global user.name "your name"
git config--global user.email [email protected]
git config--global color.ui true
git config--global core.editor vi
git config--global alias.lol "log--graph--all" set alias so that LOL is your new command.
2. Basic use
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 is used to interactively choose which changes need to be commit
git commit-m "log Message"
Or
Git commit-a automatically checks 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
A summary of git log--stat display changes
git log--graph only shows the current branch
git log--graph--all shows all branch's
git log--graph--all--decorate Show Branch's name
git log--pretty=oneline, short, full, fuller output log in different form
git log--pretty=format: "%h-%an,%ar:%s" is 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
Git makes patches
The concrete steps are written in the http://hovertree.com/menu/git/
3. Commit Range
In git, we often need to make a commit range, like Git log, to show changes in a range.
In addition to the man gitrevisions, there is also a description on this site, especially for double dot and triple dot
Http://git-scm.com/book/ch6-1.html
Http://stackoverflow.com/questions/462974/whats-the-difference-between-and-in-git-commit-ranges
And this syntax, in git log and git diff two cases, there are different meanings.
More Git articles: http://hovertree.com/menu/git/
in git log,
git log ^r1 R2 represents the display from R2 to root, but removing R1 to root and R2 to root is duplicated.
This can also be represented as git log r1. R2.
Git log r1...r2 indicates the display from R1 to root, R2 to root, but removes the part they share.
As I understand it, the previous one shows a branch on the tree. The second one shows two branches.
In git diff
The purpose of Git diff is to compare the differences between the two commits.
Git diff a B and git diff a. B is the same, it shows the difference between the two.
Git diff A ... b and Git diff $ (git-merge-base A b) b. is to show what changes have been made to the B branch.
Sometimes this command is, git merge-base a B
On one branch, but not on the other branch.
git log local_copy ^kernel
This allows you to merge before you see what you have to commit.
This command is used to look at the Local_copy branch, but not on the kernel branch.
4. Branch
1. Display Branch
Git branch
Git branch-v shows detailed information.
Git branch--merged
2. Create Branch
Git branch Testing
Or
Git checkout-b New_brach
This creates new and switches to New_brach.
There is also a way to create a branch
Git branch branch_name b42294309188d57bf3398ed35660170a237d8c0a
Note that the long string behind this is the SHA1 code for each commit.
3. Switch to a branch
git checkout Testing
4. Graphical display of branch information
Gitk
GITK--all
5. Merge
First, go to the branch you want to merge into, such as
git checkout Master
The general will merge to master.
and then call
Git merge Testing
This will merge the changes on the testing branch.
6. Delete Branch
All right, this branch, cut it out.
git branch-d Testing
7. Handling Conflict
During the merge process, you will typically encounter conflict.
Start by using GIT status to see which files have conflicts.
You can modify the files individually, or you can use Git mergetool to modify them.
When all is well modified, use Git commit.
8. See what branch merge is coming in and what's not
Git branch--merged
Git branch--no-merged
For example, we checkout to master, with--no-merged can see which branch changes are not to master.
5. Stash
Git stash is used to back up the contents of the current workspace. Read the relevant content from the most recent commit and make the workspace guarantee consistent with the last commit.
You can use git stash multiple times to save your current changes.
Git list can see how many times it's been saved.
linux-2.6$ git stash List
[Email protected] {0}: WIP on 3.0:02f8c6a Linux 3.0
[Email protected] {1}: WIP on pci-fix:79eefa4 Optimize the resource overlap check
[Email protected] {2}: WIP on pci-fix:02f8c6a Linux 3.0
[Email protected] {3}: WIP on 3.0:02f8c6a Linux 3.0
Git stash Save "name"
Git stash
Both of these are the current changes, and if you have name, you can add a label that is easy to identify.
Git stash apply is used to restore the most recent modification.
git stash apply [email protected]{1} to restore the specified changes.
git stash pop [email protected]{1} acts like Git stash apply.
Git stash pop removes a record from the stash stack, and git stash apply does not.
Git stash clear empty stack.
6. Tag
1. Display tag
Git tag shows all the tags
Match display
$ git tag-l v3.0*
v3.0
V3.0-rc1
V3.0-rc2
V3.0-rc3
V3.0-rc4
V3.0-rc5
V3.0-rc6
V3.0-rc7
2. Display details of a tag
Git show v3.0
3. Create tag
git tag-a v1.4-m "my version 1.4"
git tag-s v1.5-m "my version 1.5"
This is going to add a PGP signature.
For a-s tag, you can
Git tag-v v1.5
To verify this tag, of course you need to have each other's PGP public key.
git tag v1.4-lw
This is a lightweight tag.
git tag-a v1.2 SHA
tag for a specified SHA, the default is head
Git push Origin v1.2
Git push Origin--tags
By default, tag information is not sent to the far end.
The first command sends a specified tag to the far end.
The second command sends all tags to the far end.
7. Remote Repository
https://github.com/This online can offer to build a free git repo
Remote repo is used to co-operate with multiple individuals. Well... , more advanced.
Display information for remote repo
Git remote
Git remote-v
git remote show origin
Add another remote library
git remote add localname URL
That means using this localname to represent the URL.
Then you can download the code from the remote
git fetch localname
The default Glone after local head is track on the Origin/master,
So if you want to work on other branch, you need to set up a branch locally first.
Git branch--track feature origin/feature
This means that there is a local branch called feature, this is track origin/feature.
To view remote conditions
git remote show origin
Upload changes, if you have permission, you can upload your own updates to remote
Git push Origin Master
It means push to Origin, the master branch of the remote tree.
git push origin:master
is to delete the remote branch
Download other updates?
Git pull
Download the update and then merge directly.
When the local git repository is updated, we need to synchronize with the repository on the remote server.
Usually do this
git fetch will sync state
Git fetch-p can empty a branch that is not already in the remote
Git branch-v can see the state of the branch in the local repository.
Git Branch-av can see the state of the remote and local branches
git checkout branchname to the local branch you want to update
Git rebase origin/branchname This allows local commits to be removed and re-apply to the newest place.
8. Some Tips
1. If you edit a version, you find that a feature is not working, or there is a bug. But you know that a previous version is good.
git bisect start
Git bisect bad now this version is broken
git bisect good good_commit good_commit This version is good
Next compile, test. If it's good,
git bisect good
If it's not good,
git bisect bad
So git will give you an intermediate version of the output that you can continue to test.
Found an error, with
git bisect reset reverts to the original version.
2. Git commands automatically complete in bash
Http://progit.org/book/ch2-7.html
Copy the Git-completion.bash to the/etc/bash_completion.d/git
3. Git alias
git config--global alias.co checkout
4. Pack with Git
Git Archive Master | gzip > master.tar.gz
Pack the master this branch.
5. Cleanup
Git takes more time and slows down. Then you can use the following command to optimize.
Git gc-cleanup unnecessary files and optimize the local repository
Git-repack-pack unpacked objects in a repository
http://roucheng.cnblogs.com/
Http://www.cnblogs.com/roucheng/p/texiao.html
git command Summary