♠ Posted by NN TRUNG at 18:14
One thing you will quite often do in Git if that team work is to check those who commit to the project you are working on, and how you undo previous commit if you feel the lack of a collective certain information in advance commit to supplement.
See git log
To view a history of previous commits, you use the command
git log
is to be found.$ Git log commit 3f1ef84ada3dfd936735d8724f9bbb3437c77b19 Author: Thach Pham <contact@thachpham.com> Date: Tue 21 Apr 2015 17:16:37 -0700 Hihi commit 6e729a49a36b31919daa6263f8f98f3a59d5bab3 Author: Thach Pham <contact@thachpham.com> Date: Tue 21 Apr 2015 14:47:47 -0700 First commit on Github
You see? Every commit has a separate checksum, and it can also indicate who commit to and commit to how much day, any time.
Also, you can add the parameter
-p
to show details of a commit.$ Git log -p commit 3f1ef84ada3dfd936735d8724f9bbb3437c77b19 Author: Thach Pham <contact@thachpham.com> Date: Tue 21 Apr 2015 17:16:37 -0700 Hihi diff --git a / README.md b / README.md db7e814..e08f24f index 100644 --- A / README.md +++ B / README.md @@@@-1 +1 - # Git co Huong dan ban + Hhih \ n diff --git a / faq.html b / faq.html 100644 new mode file Index 0000000..e69de29 commit 6e729a49a36b31919daa6263f8f98f3a59d5bab3 Author: Thach Pham <contact@thachpham.com> Date: Tue 21 Apr 2015 14:47:47 -0700 First commit on Github diff --git a / README.md b / README.md 100644 new mode file Index 0000000..db7e814 --- / Dev / null +++ B / README.md @@@@-0.0 +1 + # Git co Huong dan ban
Note: If the log is too long, use the up and down arrow keys to read and press Ctrl + Z to exit.
Or if you'd just like to see the most recent commit is one more parameter
-1
in.
You also could use some additional options for optimal viewing logs after the process than reading log.
--since
,--after
: See the commits since a certain date.--until
: See the previous commit certain date.--author
: See the commit of someone.--grep
: Filtering the strings in the log and printed.
For example:
$ Git log --author=contact@thachpham.com --pretty = "% s" Hihi First commit on Github
Cai
--pretty
is what I will say below.
Filter log with --pretty
Parameters
--pretty
very useful if you want to filter certain whether an object in the commit history, like only see messages commit or just watch people commit mail.
Using parameters
--pretty
you must write its tag attached the following: $ Git log --pretty = "% tag"
The
%tag
must be placed in quotation marks, and you can use multiple %tag
differently.
List of
%tag
:%H
- Commit hash%h
- abbreviated commit hash%T
- Tree hash%t
- abbreviated hash tree%P
- Parent hashes%p
- abbreviated parent hashes%an
- Author name%ae
- Author e-mail%ad
- Author date (format respects the -date = option)%ar
- Author date, relative%cn
- committer name%ce
- committer email%cd
- committer date%cr
- committer date, relative%s
- Subject
For example:
$ Git log --pretty = "% secure -% s" Thach Pham - Hihi Thach Pham - First commit on Github
More tips see beautiful log
You can see when typing git log parameters without accompanying it appeared difficult to see. But there is one way you can do neat the default log, and add color to it so you look better.
First you copy this command to set.
git config --global alias.lg "--color --graph log --pretty = format:"% h% Creset Cred% -% C (yellow)% d% s% Cgreen Creset% (% cr)% C ( bold blue) <% Security>% Creset '--abbrev-commit "
Now to see the log, you just need to type
git lg
to see. You can combine it with the parameters above.The most important thing is with this view, you can see the HEAD (pointer of current branch) that later when you learn to branch you will find it very useful.Undo Commit
If you need to remove the previous commit and needed to commit to undo, you can use the parameter
--amend
in command git commit
.$ Git log --pretty = "% s" Hihi First commit on Github $ Git commit -m --amend "Hehe" [Master 3682e56] Hehe Date: Tue 21 Apr 2015 17:16:37 -0700 2 files changed, 1 insertion (+), 1 deletion (-) create mode 100644 faq.html $ Git log --pretty = "% s" Hehe First commit on Github
Note that undo means you commit step back last time, so if you need any additional files to commit, please put that file in front Staging Area.
Skip files from Staging Area
If you've put a certain file in Staging Area but now you want to remove it from here to not commit so it could be used commands
git reset HEAD tên_file
. What is the next HEAD section branching (Branch) I'll explain.Epilogue
In this article you learned how to manipulate to review the history of commits to track better commits, and how you restore operation involves Commit. However, you can see that I have said over the management of the Git version yet? Never, right? Okay, so in the following article I will guide you to become familiar with the features Tagging (tick) of Git and this is how we manage each version of code.
0 nhận xét:
Đăng nhận xét