译者:zhanhailiang 日期:2015-01-21
Original link: Tips for intermediate Git Users
Store content to stashes, index and file system 10. Staging Area
Discard all operations of staging area:
$ git stash# Do something...$ git stash pop
11. Interactively add changes to staging area
$ git add -i staged unstaged path*** Commands *** 1: status 2: update 3: revert 4: add untracked 5: patch 6: diff 7: quit 8: helpWhat now>
Storing/retrieving from the File System
Slightly.
View git log 13. View the Operations log
To view the most recently submitted action log:
$ git log -p
View only the list of recently modified files:
$ git log --stat
14. Search Logs
To query the update log for the specified author:
$ git log --author=Andy
Filter logs by searching for submitted comment keywords:
$ git log --grep="Something in the message"
To query the modification log for the specified file:
$ git log lib/foo.rb
View the differences between branch feature/132 and branch feature/145, each of which differs from the master branch:
$ git log feature/132 feature/145 ^master
You can also query the operation log for a specified time period (the time format supports Activesupport style):
$ git log --since=2.months.ago --until=1.day.ago
15. View information about a specific version
$ git show 12a86bc38 # By revision$ git show v1.0.1 # By tag$ git show feature132 # By branch name$ git show 12a86bc38^ # Parent of a commit$ git show 12a86bc38~2 # Grandparent of a commit$ git show [email protected]{yesterday} # Time relative$ git show [email protected]{2.hours.ago} # Time relative
Selecting a Range
To view the modification logs that are not pushed by the local warehouse:
$ git log origin/master..new# [old]..[new] - everything you haven‘t pushed yet
Rollback with bug fix 17. Rolling back modifications
Rollback directly to the most recent version of the Local repository: (If your changes have not been submitted)
$ git reset HEAD lib/foo.rb
Rollback to the most recent version of the Local repository: (If your changes were submitted)
If you want to roll back to the previous version before the last commit:
$ git commit--amend
If you are submitting multiple code before rolling back:
$ git checkout feature132
$ git reset--hard head~2
18. Branching operations
Master commits three modifications, and now wants to move the last three modifications to the branch experimental and cancels the last three changes to the master branch:
$ git branch experimental # Creates a pointer to the current master state$ git reset --hard master~3 # Moves the master branch pointer back to 3 revisions ago$ git checkout experimental
Interactive rebasing
Slightly.
Cleaning up
Slightly.
Other precautions 21. View the SHA-1 logging for the last query
$ git reflog$ git log -g # Same as above, but shows in ‘log‘ format
22. Branch naming
$ # Generate a changelog of Release 132$ git shortlog release/132 ^release/131$ # Tag this as v1.0.1$ git tag v1.0.1 release/132
23. Query the individual lines of the specified file to edit the log
$ git blame FILE
Database Maintenance
Slightly.
25. Rebuilding a lost Branch
$ git branch experimental SHA1_OF_HASH
[Translate] 25 tips for intermediate git users (bottom)