Programing

최근 실행 된`git pull`의 날짜와 시간을 어떻게 확인하나요?

lottogame 2020. 9. 20. 10:32
반응형

최근 실행 된`git pull`의 날짜와 시간을 어떻게 확인하나요?


최근 git pull에 실행 된 날짜와 시간을 어떻게 확인 합니까? 뭔가 잘못되었을 때 서버에서 코드가 언제 변경되었는지 자주 알아야합니다.


git show명령은 가장 최근 커밋 날짜를 보여줍니다. 이것은 커밋이 로컬 저장소로 가져온 날짜가 아니지만 Git은 이러한 가져 오기 정보를 유지하지 않습니다.

서버에있는 파일의 ctime (생성 시간)을 사용하여 마지막 풀 시간을 찾을 수 있습니다. 예를 들면 :

ls -lct

가장 최근의 순서로 정렬 된 각 파일의 ctime을 표시합니다.


stat -c %Y .git/FETCH_HEAD

해당 파일의 마지막 수정에 대한 유닉스 타임 스탬프를 제공합니다. Git은 가져올 것이없는 경우에도 가져 오거나 가져올 때마다 FETCH_HEAD 파일을 작성합니다.


직감으로 나는 "stat -c % y .git / FETCH_HEAD"를 시도했고 그 당시 사람이 읽을 수있는 인쇄물을 얻었다.

> stat -c %y .git/FETCH_HEAD
2015-02-24 17:42:08.072094410 -0500

또한 ~ / .gitconfig 파일 when = !stat -c %y .git/FETCH_HEAD[alias]섹션에 추가 할 수 있습니다 (git repo에서 다음 명령 줄을 실행하여 자동으로 수행하는 것이 가장 안전합니다).

git config --global alias.when '!stat -c %y .git/FETCH_HEAD'

그러면 언제든지 새로운 "명령"을 사용하여이 정보를 찾을 수 있습니다.

> git when
2015-02-23 15:07:53.086254218 -0500

[그런 다음 "man stat"를 수행하게되었고, 'stat'프로그램에 사용할 수있는 다른 % 매개 변수가 많이 있음을 발견했습니다. YMMV.]


베어가 아닌 저장소 (그리고 베어 저장소 git pull는를 의미하지 않음 )에서 git은 브랜치 팁의 모든 변경 사항과 현재 브랜치 아이디어를 .git/logs. 을 사용하여 볼 수 있습니다 git log -g.

그러나 로그 파일에 타임 스탬프가 있어도이를 git log -g인쇄하는 것으로 나타나지 않습니다 . 그러나 .git/logs/HEAD예를 들어 살펴보면 형식이 구문 분석하기가 매우 간단하다는 것을 알 수 있습니다. ref (또는 HEAD)가 무엇에서 변경되었는지, 변경되었는지, 누가 변경했는지, 언제 변경했는지, 활동 메시지로 구성됩니다.


git show -1 --stat  

이 git 명령은 메시지와 함께 최신 변경 사항 커밋 시간 및 날짜를 ​​보여줍니다.


파이썬 사용 : python -c "import os;print os.stat('.git/FETCH_HEAD').st_mtime"


python -c "import os, datetime ;print datetime.datetime.fromtimestamp(os.stat('.git/FETCH_HEAD').st_mtime)"

또는

python3 -c "import os, datetime ;print(datetime.datetime.fromtimestamp(os.stat('.git/FETCH_HEAD').st_mtime))"

$ # for the latest pull even if there's nothing new
$ stat -c %y .git/FETCH_HEAD
2017-12-15 11:24:25.000000000 +0100
$ 
$ # for records of updated references
$ git reflog --date=iso
db2bba84 (HEAD -> master, origin/master, origin/HEAD) HEAD@{2017-12-14 11:28:39 +0100}: pull: Fast-forward
37fe73ad HEAD@{2017-12-03 17:09:32 +0100}: pull: Fast-forward
c4107fcd HEAD@{2017-11-27 18:53:40 +0100}: clone: from https://github.com/macports/macports-base
$ 
$ # for a more detailed view of the latter
$ git log -g
commit db2bba84d5e8cd82ec94a19129deb91ef62287bb (HEAD -> master, origin/master, origin/HEAD)
Reflog: HEAD@{0} (me <me@machine.local>)
Reflog message: pull: Fast-forward
Author: Ryan Schmidt <ryandesign@macports.org>
Date:   Wed Dec 13 10:23:47 2017 -0600

    portutil.tcl: Fix renames that supply the -force option

    Treat $options as a list not as a string.

    See: https://trac.macports.org/ticket/55492

[snip]

크로스 플랫폼 (OSX / Linux) Bash 솔루션

@smooves답변 : https://stackoverflow.com/a/9229377/622276 및 댓글에서 크게 영감을 받았습니다 .

하지만 내 자신의 bash 프롬프트 git 통합을 유지하고 있습니다.

출처 : https://github.com/neozenith/dotfiles/blob/master/bash-scripts/function_parse_git_prompt.sh

msys version in Git Bash for Windows works identical to the linux version.

I'm compiling the cross platform options into a case statement. So it will fork a fetch process on any git repo I navigate into that is older than fifteen minutes since last fetch so the rest of my prompt script knows if I have stuff to pull.

Git radar used to to this but it required saving a file with timestamp of when the last fetch was called. This writes no temporary files.

git rev-parse --show-toplevel just means if I'm anywhere in a git repo it will get the repo root so we can reference the .git folder path.

# No repo == no more work 
local REPO_ROOT=`git rev-parse --show-toplevel 2> /dev/null`
if [[ -n $REPO_ROOT && -e "$REPO_ROOT/.git/FETCH_HEAD" ]]; then

    case $OSTYPE in
      darwin*)
        local LAST_FETCH="$(stat -f '%m' $REPO_ROOT/.git/FETCH_HEAD)" 
        local FETCH_THRESHOLD="$(date -v-15m +%s)"  
      ;;
      *)
        local LAST_FETCH="$(stat -c %Y $REPO_ROOT/.git/FETCH_HEAD)" 
        local FETCH_THRESHOLD="$(date -d'15 minutes ago' +%s)"  
      ;;
    esac

    # Fork fetch process in background
    if [[ $LAST_FETCH -lt $FETCH_THRESHOLD ]]; then
      git fetch --all --quiet --prune 2> /dev/null &
    fi

fi

As suggested by user: https://stackoverflow.com/users/83646/smoove, you can find when git pull was last called on the repo by checking the modification timestamp of: .git/FETCH_HEAD as: git writes the .git/FETCH_HEAD file every time you pull or fetch, even if there was nothing to pull.

Example: {master} vinegupt@bhling69(/imsgit_local/work/vinegupt/ims_18.5a/ims_common)$ stat -c %y .git/FETCH_HEAD

2018-02-12 02:01:50.487160386 +0530

참고URL : https://stackoverflow.com/questions/2993902/how-do-i-check-the-date-and-time-of-the-latest-git-pull-that-was-executed

반응형