Historial de commits#

  • Última modificación: Mayo 14, 2022

Adaptado de: https://git-scm.com/book/en/v2/Git-Basics-Viewing-the-Commit-History

Preparación del proyecto

[1]:
!mkdir git-demo
%cd git-demo
/workspace/git/git-demo
[2]:
%%sh
git init

git config user.email "you@example.com"
git config user.name "john doe"

touch file_1.txt file_2.txt
git add *.txt
git commit -m 'create file_1.txt file_2.txt files'
Initialized empty Git repository in /workspace/git/git-demo/.git/
[master (root-commit) fc94826] create file_1.txt file_2.txt files
 2 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 file_1.txt
 create mode 100644 file_2.txt
Working      Staging    .git
Tree         Area       directory
-------------------------------------------------------------------------------------
file_1.txt              ## create file_1.txt file_2.txt files
  (emtpy)               file_1.txt
file_2.txt                (empty)
  (empty)               file_2.txt
                          (empty)
[3]:
%%sh
echo 'Hola mundo cruel!' > file_2.txt
git add file_2.txt
git commit -m 'modify file_2.txt file'
[master 312c0b4] modify file_2.txt file
 1 file changed, 1 insertion(+)
Working                Staging    .git
Tree                   Area       directory
-------------------------------------------------------------------------------------
file_1.txt                        ### create file_1.txt file_2.txt files
  (emtpy)                         file_1.txt
file_2.txt                          (empty)
  Hola mundo cruel!               file_2.txt
                                    (empty)
                                  ### modify file_2.txt file
                                  file_2.txt
                                    Hola mundo cruel!
[4]:
%%sh
touch file_to_ignore.txt
echo "file_to_ignore.txt" > .gitignore
git add .gitignore
git commit -m 'create .gitignore'
[master e5d98b0] create .gitignore
 1 file changed, 1 insertion(+)
 create mode 100644 .gitignore
Working                 Staging    .git
Tree                    Area       directory
-------------------------------------------------------------------------------------
file_1.txt                         ### create file_1.txt file_2.txt files
  (emtpy)                          file_1.txt
file_2.txt                           (empty)
  Hola mundo cruel!                file_2.txt
file_to_ignore.txt                   (empty)
  (empty)                          ### modify file_2.txt file
.gitignore                         file_2.txt
  file_to_ignore.txt                 Hola mundo cruel!
                                   ### create .gitignore
                                   .gitignore
                                     file_to_ignore.txt
[5]:
!git log
commit e5d98b0e2eab98fe6af0380507197fb456491ea9 (HEAD -> master)
Author: john doe <you@example.com>
Date:   Wed Jun 8 20:47:38 2022 +0000

    create .gitignore

commit 312c0b41dba7a8ff1f4b04949a19064b9bc73c63
Author: john doe <you@example.com>
Date:   Wed Jun 8 20:47:37 2022 +0000

    modify file_2.txt file

commit fc9482686d53e50f7bef2171211749bf5672d4b6
Author: john doe <you@example.com>
Date:   Wed Jun 8 20:47:37 2022 +0000

    create file_1.txt file_2.txt files
[6]:
# -p / --patch,  -2: las últimas dos entradas.
!git log -p -2
commit e5d98b0e2eab98fe6af0380507197fb456491ea9 (HEAD -> master)
Author: john doe <you@example.com>
Date:   Wed Jun 8 20:47:38 2022 +0000

    create .gitignore

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..7a6b6a0
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+file_to_ignore.txt

commit 312c0b41dba7a8ff1f4b04949a19064b9bc73c63
Author: john doe <you@example.com>
Date:   Wed Jun 8 20:47:37 2022 +0000

    modify file_2.txt file

diff --git a/file_2.txt b/file_2.txt
index e69de29..b9cfaf9 100644
--- a/file_2.txt
+++ b/file_2.txt
@@ -0,0 +1 @@
+Hola mundo cruel!
[7]:
!git log --stat
commit e5d98b0e2eab98fe6af0380507197fb456491ea9 (HEAD -> master)
Author: john doe <you@example.com>
Date:   Wed Jun 8 20:47:38 2022 +0000

    create .gitignore

 .gitignore | 1 +
 1 file changed, 1 insertion(+)

commit 312c0b41dba7a8ff1f4b04949a19064b9bc73c63
Author: john doe <you@example.com>
Date:   Wed Jun 8 20:47:37 2022 +0000

    modify file_2.txt file

 file_2.txt | 1 +
 1 file changed, 1 insertion(+)

commit fc9482686d53e50f7bef2171211749bf5672d4b6
Author: john doe <you@example.com>
Date:   Wed Jun 8 20:47:37 2022 +0000

    create file_1.txt file_2.txt files

 file_1.txt | 0
 file_2.txt | 0
 2 files changed, 0 insertions(+), 0 deletions(-)
[8]:
!git log --pretty=oneline
e5d98b0e2eab98fe6af0380507197fb456491ea9 (HEAD -> master) create .gitignore
312c0b41dba7a8ff1f4b04949a19064b9bc73c63 modify file_2.txt file
fc9482686d53e50f7bef2171211749bf5672d4b6 create file_1.txt file_2.txt files
[9]:
!git log --pretty=format:"%h - %an, %ar : %s"
e5d98b0 - john doe, 1 second ago : create .gitignore
312c0b4 - john doe, 2 seconds ago : modify file_2.txt file
fc94826 - john doe, 2 seconds ago : create file_1.txt file_2.txt files

Opciones para –pretty=format#

Specifier   Description
-------------------------------------------------------------------------------

%H          Commit hash

%h          Abbreviated commit hash

%T          Tree hash

%t          Abbreviated tree hash

%P          Parent hashes

%p          Abbreviated parent hashes

%an         Author name

%ae         Author email

%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
[10]:
!git log --pretty=format:"%h %s" --graph
* e5d98b0 create .gitignore
* 312c0b4 modify file_2.txt file
* fc94826 create file_1.txt file_2.txt files

Opciones comunes#

Opción     Descripción
-------------------------------------------------------------------------------

-p               Show the patch introduced with each commit.

--stat           Show statistics for files modified in each commit.

--shortstat      Display only the changed/insertions/deletions line from the
                 --stat command.

--name-only      Show the list of files modified after the commit information.

--name-status    Show the list of files affected with added/modified/deleted
                 information as well.

--abbrev-commit  Show only the first few characters of the SHA-1 checksum
                 instead of all 40.

--relative-date  Display the date in a relative format (for example,
                 “2 weeks ago”) instead of using the full date format.

--graph          Display an ASCII graph of the branch and merge history beside
                 the log output.

--pretty         Show commits in an alternate format. Option values include
                 oneline, short, full, fuller, and format (where you specify
                 your own format).
--oneline        Shorthand for --pretty=oneline --abbrev-commit used together.

Limitación de la salida#

[11]:
!git log --since=5.hours
commit e5d98b0e2eab98fe6af0380507197fb456491ea9 (HEAD -> master)
Author: john doe <you@example.com>
Date:   Wed Jun 8 20:47:38 2022 +0000

    create .gitignore

commit 312c0b41dba7a8ff1f4b04949a19064b9bc73c63
Author: john doe <you@example.com>
Date:   Wed Jun 8 20:47:37 2022 +0000

    modify file_2.txt file

commit fc9482686d53e50f7bef2171211749bf5672d4b6
Author: john doe <you@example.com>
Date:   Wed Jun 8 20:47:37 2022 +0000

    create file_1.txt file_2.txt files
[12]:
!git log --since=2.weeks
commit e5d98b0e2eab98fe6af0380507197fb456491ea9 (HEAD -> master)
Author: john doe <you@example.com>
Date:   Wed Jun 8 20:47:38 2022 +0000

    create .gitignore

commit 312c0b41dba7a8ff1f4b04949a19064b9bc73c63
Author: john doe <you@example.com>
Date:   Wed Jun 8 20:47:37 2022 +0000

    modify file_2.txt file

commit fc9482686d53e50f7bef2171211749bf5672d4b6
Author: john doe <you@example.com>
Date:   Wed Jun 8 20:47:37 2022 +0000

    create file_1.txt file_2.txt files
[13]:
!git log --until=1.hours

Opciones para limitar el formato

Opción     Descripción
--------------------------------------------------------------------------------

-<n>               Show only the last n commits

--since, --after   Limit the commits to those made after the specified date.

--until, --before  Limit the commits to those made before the specified date.

--author           Only show commits in which the author entry matches the
                   specified string.

--committer        Only show commits in which the committer entry matches the
                   specified string.

--grep             Only show commits with a commit message containing the string

-S                 Only show commits adding or removing code matching the string
[14]:
# --< Limpieza del área de trabajo >-------------------------------------------
%cd ..
!rm -rf git-demo
/workspace/git