Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

update version each time git push is done?

how do we do like changing version ( each +1 ) using git on each push?

example i have a 2 php file

libs/lib1.php
libs/lib2.php

on each header usually there is some information like

/**
 * LIB1.PHP
 * this libs does something like this
 * and that this is a doc for you
 * @version 145
 * @todo something todo
 * @author DAMS
 */

/**
 * LIB2.PHP
 * this libs does something like this
 * and that this is a doc for you
 * @version 445
 * @todo something todo
 * @author DAMS
 */

can we search and add +1 do version every time we push?

like image 992
Adam Ramadhan Avatar asked Dec 26 '10 05:12

Adam Ramadhan


People also ask

What is push in version control?

Pushing is how you transfer commits from your local repository to a remote repo. It's the counterpart to git fetch , but whereas fetching imports commits to local branches, pushing exports commits to remote branches. Remote branches are configured using the git remote command.

What is flag git push?

This option overrides the "fast forward" restriction and matches our local branch to the remote branch. The --force flag allows you to order Git to do it anyway. When you change history, or when you want to push changes that are inconsistent with the remote branch, you can use push --force .

Should you git push after every commit?

This is why you should commit often and push always. If you commit, push. Ideally, you should commit every time you check off a task. You should never commit a half-written function without first writing comments and perhaps even some pseudo code.


1 Answers

What you're asking for is essentially keyword expansion. To start, take a look at the Git FAQ question "Does git have keyword expansion?". It says:

Keyword expansion is not recommended. Keyword expansion causes all sorts of strange problems and isn't really useful anyway, especially within the context of an SCM. You can perform keyword expansion outside of git using a custom script. The Linux kernel export script does this to set the EXTRA_VERSION variable in the Makefile.

See gitattributes(5) if you really want to do this. If your translation is not reversible (eg SCCS keyword expansion) this may be problematic. (Hint: the supplied $Id$-expansion puts the 40-character hexadecimal blob object name into the id; you can figure out which commits include this blob by using a script like this.)

See here for a discussion, and here on how GIT may help anyway.

So git does have something like keyword expansion, though it's not recommended. Git also doesn't have the concept of a "file revision" (which is what your @version number appears to be), so this wouldn't be able to give you exactly what you're asking for.

You could alternatively create a hook (probably a pre-receive hook?), that would increment the version for you. This is just an executable (so it can be a shell/ Python/ Perl/ Ruby/ whatever-you're-comfortable-with script) that'll get executed automatically when you do a push. See the githooks man page.

Your hook script would:

  • Identify files that are about to be modified.
  • Of those, find ones that contain the pattern @version \d+
  • Increment the version. You want to increment the value in the parent commit, not the value that's currently in the file!

Note that this is at least as bad as using the keyword expansion that the Git FAQ recommends against, and possibly much worse. This will likely to lead to annoying merge conflicts. You could also easily end up with misleading version numbers in your code, especially if you ever have to commit a bugfix to an older version, though it will probably also happen whenever you merge changes from multiple repos/branches (which is pretty common with most git workflows) if you aren't careful.

like image 189
Laurence Gonsalves Avatar answered Sep 19 '22 21:09

Laurence Gonsalves