1. Git features and status :
Features :
You can submit updates or compare with historical versions even when you are not connected to the Internet.
Almost all operations can be performed locally.
Maintain data integrity at all times: All files and directories will be checked and calculated by the sha-1 algorithm. They will be used as data unique identifiers and indexes.
Don't worry about data loss once you commit the snapshot.
git has three states: modified, staged, and committed
Modified: A file has been modified but not yet staged.
Staged: Modified files are placed in the manifest to be saved on the next commit. git add
Committed: The file has been safely saved in the local database. git commit
2. Basic commands
1. User information
git config --global user.name "xxx"
git config --global user.email [email protected]
2. View configuration information
git config --list
3. View a certain configuration information
git config user.name
4. Get help
git help
git branch --help //information about a command
5. Clone from an existing repository :
git clone url 或 git clone url rename
6. Check the current status of the file :
git status
7. Track new files :
git add file puts the modified file in the staging area
8. Ignore files :
build .gitignore
#comment
/dir directory
!filename except for a file
9. Check which parts of the files that have not been staged have been updated :
git diff
10. Differences between the staged file and the last commit :
git diff --cached
11. Submit an update :
git commit
Before submitting, you need to confirm which files have not been git added, otherwise these unstaged changes will not be recorded when submitting.
git commit -a
Skip using the staging area, and git will stage all tracked files and commit them together.
12. Remove files :
First use rm file to manually delete the file, and then use git rm file to record the operation of removing the file.
At the final commit, the file is no longer in version management.
git rm -f Force delete to prevent loss of modified content after deletion.
If you want to delete the file from the git repository (that is, delete it from the staging area), but still keep it in the working directory, that is, delete the track without deleting the file, so that you can add the --cached parameter in the .gitignore file later:
git rm --cached file
13. View the commit history :
git log
git log -2 //Display the history of the last 2 commits
git log -p //Display the content difference of each commit, + is a new line, - is a deleted line.
git log --stat //Display modified files, increase or decrease line number statistics
git log --pretty=oneline|short|full|fuller //Display information from less to more
git log --pretty=format:"%h - %an - %cn" //format can customize the display format by itself
git log --since=3.day //Display commits within 3 days
git log --committer=shensy //Display all records submitted by someone
git log --grep=fix //Search for keywords in commit records
There are many more parameters see git log --help
14. Modify the last commit :
git commit --amend //modify the comment from the last commit
The comment from the last submission can be modified on this basis, but the comment automatically generated by git must not be moved, otherwise it will not recognize the original patch and will create a new patch.
15. Cancel the files that have been temporarily stored :
For files that have been git added to the staging area, you can use:
git reset HEAD file unstages it.
16. Cancel the modification :
git checkout -- file
17. View the remote warehouse :
git remove -v //View remote warehouse information. After cloning a project, you can see at least one remote library named origin (git uses origin to identify remote libraries by default).
18. Add a remote warehouse :
git remote add shortname url
19. Grab from the remote warehouse :
git fetch remote-name
20. Push data to the remote warehouse :
git push remote-name branch-name
If someone else has pushed some updates before the push, the push back is rejected. You must get the latest update before you can push it again.
21. View remote warehouse information :
git remote show remote-name
22. Renaming of remote warehouse :
git remote rename remote-name rename
23. Label :
If you reach an important stage and want to remember that particular commit snapshot forever, you can tag it with git tag. The tag command basically permanently bookmarks that particular commit, allowing you to compare it with other commits in the future. Usually, you'll put a tag when you're slicing a release or delivering something.
24. Display labels :
git tag // show all
git tag -l 2012* //match by string
25. Create annotated labels :
git tag -a v1.4 -m "comment..."
26. View the version information of the label :
git show tagname
27. Create lightweight tags (without additional information) :
git tag tagname
28. Post-add label :
Query history commit first
git log --pretty=oneline
After labeling, keep up with the first few digits of the object checksum.
git tag -a v1.2 5aef25ac
29. Share tags :
In general, git push will not push tags to the remote server, only the display command will be pushed to the remote warehouse.
git push origin v1.5
git push origin --tags // push all tags at once
Others will see these labels when they pull the data.
30. Git branch :
When git creates a new branch, it creates a new branch pointer.
A special pointer called HEAD is kept in git, which is a pointer to the local branch at work.
git branch [branch_name] //Create a new branch
git checkout [branch_name] //Switch branch
git checkout -b [branch_name] //Create a new branch
git merge [branch_name] // merge branch
After merging, use git status to view the conflicting files, and the unmerged state is the unmerged state.
===== The upper part of the separation is the content in HEAD, and the lower part is the content in your merged branch.
31. Branch management :
View the last commit information of each branch:
git branch -v
git branch --merged //View merged branches
git branch --no-merged //View unmerged branches
git branch -d [branch_name] //delete local branch
git branch -D [branch_name] //Forcibly delete the local branch
32. Remote branch : Represent remote branch in the form of remote warehouse name/branch name
git checkout -b test origin/master //Switch out a branch test from the master branch of the remote origin warehouse.
33. Push :
git push remote repository name branch name
34. Tracking branch : that is, the local branch checked out from the remote branch.
git checkout --track origin/test // Track the local branch to the test branch in the origin of the remote warehouse
git checkout -b ts origin/test // Track the local branch to the test branch in the origin of the remote warehouse. After the local alias is ts tracking, the local branch will automatically push and fetch data to the remote branch during git pull and git push.
35. Delete the remote branch :
git push remote repository: remote branch // note that git push is quite dangerous
36. Rebase rebase :
Replay changes committed in one branch in another.
Never rebase updates that have already been pushed to the public repository.
git rebase [targetbranch] //Merge the commits of the target branch into the current branch (merge all changes since the target branch was created)
If prompted to handle conflicts. Once done, you can run git rebase --continue to continue until done
If you don't want to deal with it, you still have two options, one is to abandon the rebase process (run git rebase --abort), and the other is to directly replace the current branch with the targetbranch branch (git rebase --skip).
37、reset:
Through git reset, the current branch can be switched to any previous version state of this branch, that is, the so-called "backtracking". That is, the "regret medicine" of this branch is realized. That is the original intention of the version control system.
References :
http://www.cnblogs.com/kym/archive/2010/08/12/1797937.html About git rebase