简体   繁体   中英

How to get youngest revision in a Git repository

How can I get some sort of ID in a Git repository that can tell me the latest commit/push to the repository?

I've come up with the following so far; I'd like to know if this would work for the description below, or if I need something else:

rev=`git log --max-count=1 --pretty=format:%H`

I currently have a backup script for Subversion that works something like this:

  1. Get the youngest revision in the repository with svnlook youngest /path/to/repo .
  2. Create the backup file name using this revision number: dumpFile=${base}-${rev}.svndump .
  3. Check if the dump file exists. If it exists, then there is nothing to do since there has been no activity in the repository since the previous full backup; otherwise continue...

I'd like a Git full backup script that works the same way so, if I backup a rather large repo every night or every week, and there hasn't been any activity in three months across every branch, every tag, every property, then I'm not wasting additional disk space nor time repeatedly dumping the same data over and over again.

A simpler way is using git rev-list :

# latest commit in current branch
git rev-list -n1 HEAD

# latest commit in all branches
git rev-list -n1 --all

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM