I checked out a project from an internal GitLab server using Eclipse, then I pulled all the changes. When I view the history from Eclipse. (Team > show in history), it displays the full history of the project.
Now I go to the relevant project from the terminal.
/home/workspace/ProjectX/
I am trying to get the differences between 2 dates with the following command:
git diff --name-only master#{2015-10-10}..master#{2015-11-10} > /home/results/ProjectX/Changes.txt
It wont display any result for that. It displays:
warning: Log for 'master' only goes back to Tue, 10 Nov 2015.
How can I get all the differences in that date range?
In addition to that, how does Eclipse request its history from the remote server. If we can run the same command from the terminal, that should work.
Git parses dates like master#{2015-10-10} using your reflog, which doesn't appear to go back as far as you're searching. But, you can find commits for that date range anyway with rev-list:
git rev-list --since='2015-10-10' --until='2015-11-10' master
You want the files changes between the most recent and the oldest commit in that list, which we can get using head and tail. I'd like to use -n1 and --reverse, but --reverse applies after -n, so we can't.
first=$(git rev-list --since='2015-10-10' --until='2015-11-10' master | tail -1)
last=$(git rev-list --since='2015-10-10' --until='2015-11-10' master | head -1)
git diff --name-only $first..$last
Setting variables and duplicating the rev-list feels clumsy, but the pipe-y version I can come up with is sort of worse. It picks the first and last commits, converts the newline to a space using tr, replaces the new space with .. using sed, then passes the pair off to git diff.
git rev-list --since='2015-10-10' --until='2015-11-10' master | \
(head -n1 && tail -n1) | \
tr '\n' ' ' | \
sed 's/ /../' | \
xargs git diff --name-only
Related
How to get total number of lines of code (added and deleted) of a github user's pull requests to a certain github repo (optionally within a period of time)? Is there an easy way without writing code (or a hard way anyway)?
https://ossinsight.io/ is cool but it does not seem to have a way to run custom SQL query on the website.
A possible approach (to be refined) would be to use the GitHub CLI gh, from within a local clone:
C:\Users\vonc\git\git>gh pr diff --patch 1382 | grep -E "file.? changed, "
2 files changed, 29 insertions(+), 13 deletions(-)
Which refers to PR 1382 of the git/git repository.
The other approach would be to use a GraphQL query (similar to this one) and start querying remote pull request that way.
The OP yijiem reports in the comments using the first approach with:
$ gh pr list --search "is:merged author:<name>" --json number --jq '.[].number' | \
awk '{ system("gh pr diff --patch " $0) }' | \
grep -E "file.? changed" | \
awk '{ i+=$4; d+=$6 } END { print i,d }'
The --json output format and --jq query option of gh are really nice!
8 hours ago
I am using autotools/eclipse/linux.
I want to run a script to increment the build number in a header file every time I hit the build button. Do I add it in the Makefile.am? What is the syntax for this?
You can do it like this: add it to the all target so that it gets run every time, and declare it as .PHONY so that make doesn't try to relate it to an existing file.
all: update-build-number
.PHONY: update-build-number
update-build-number:
$(srcdir)/my_increment_script
This may be useful to others trying to do version control with git and automate their version numbering
Here is my number generator:
#!/bin/sh
#echo "Test version of version_script runs OK!"
majorversion=1
#echo "Commits"
#git rev-list HEAD
lastmerge=`git rev-list --merges HEAD | head -n1`
#echo "Last Merge"
#echo $lastmerge
#echo "Merges (Sub version)"
#git rev-list --merges HEAD
subvn=`git rev-list --merges HEAD | wc -l`
#echo $subvn
#echo "Commits+1 since last merge (Sub sub version)"
subsubvn=`git rev-list HEAD | grep -B99999 -e$lastmerge - | wc -l`
#echo $subsubvn
#echo "No merges"
#git rev-list --no-merges HEAD
#git rev-list --no-merges HEAD | wc -l
#echo $majorversion.$subvn.$subsubvn > versionnumfile
echo $majorversion.$subvn.$sub
Major version is hard coded (at the moment), sub version is number of merges, sub-sub version is number of commits (+1) since last merge
I want to add a hook that logs something to the effect of "Hey, I'm about to deploy such-and-such commit." Something like:
before "deploy:update_code" do
logger.info "Deploying #{revision}"
end
Except "revision" in this context seems to yield a ref name (i.e. "master") rather than a commit ID. What construct can I use to get the sha1?
To get the ref, you'll need to shell out to Git:
Here's an example from one of my own projects, where master is fully up-to-date and pushed, and my clean_architecture branch isn't.
~/api git:(clean_architecture) $ git show-ref master
349dabbffec0713ac0fc70cf991dbaff6412ad2b refs/heads/master
349dabbffec0713ac0fc70cf991dbaff6412ad2b refs/remotes/origin/master
~/api git:(clean_architecture) $ git show-ref clean_architecture
14afae560ace128a13336ca01ff2391b678fadaf refs/heads/clean_architecture
bc78906ad0b2814dbc6225b2e14155b66eedffd0 refs/remotes/origin/clean_architecture
Taking that on-board, I'd suggest something like the following to grab the remotely pushed ref hash (as that's the only one the Capistrano 3 can see, Capistrano will do a check like this internally, but you can't access the ref, and will complain if these two values differ, anyway)
First, on the command line:
$ git show-ref clean_architecture | tail -1 | cut -f1 -d ' '
bc78906ad0b2814dbc6225b2e14155b66eedffd0
$ git show-ref clean_architecture | tail -1 | awk '{print $1}'
bc78906ad0b2814dbc6225b2e14155b66eedffd0
(there's about a million ways to do this on linux)
Secondly in Ruby:
$ irb --simple-prompt
>> `git show-ref #{fetch(:branch)}`
=> "349dabbffec0713ac0fc70cf991dbaff6412ad2b refs/heads/master\n349dabbffec0713ac0fc70cf991dbaff6412ad2b refs/remotes/origin/master\n"
Which let's us know we can split this up really easily in Ruby land, and not need cut or awk:
$ irb --simple-prompt
>> `git show-ref #{fetch(:branch)}`.split.first
That should be pretty close, and pretty-portable (where as cut and awk, and splitting that up in the shell with pipes, etc is quite *nix specific and unlikely to work well on Windows)
Drop that in your before task, and you should be set.
I have a CSS file with thousands of lines of code. I want to see when a specific line/chunk of code was changed, without going back and reviewing each revision that changed this file (that will take a looooong time!)
Is there a way, using either TortoiseHg, Eclipse with a Mercurial plugin, or command-line, to view the history of a specific piece of code?
The correct answer is hg grep (Mercurial grep page).
More deep:
hg grep --all "PATTERN" FILENAME
Sample output:
>hg grep --all "textdomain" functions.php
functions.php:2:-:load_theme_textdomain('fiver', get_template_directory() . '/translation');
functions.php:2:+:load_theme_textdomain('fiver', get_template_directory() . '/languages');
functions.php:1:+:load_theme_textdomain('fiver', get_template_directory() . '/translation');
(in order - filename, revision, action, string in this revision)
You can use:
hg annotate <file>
to find out in which revision line was changed and then use same command with -r <revision> at the end to go backwards through revisions.
I don't think there is an option to view a specific part of a file. But to see the differences of the total file over several revisions you can use hg diff:
hg diff -r firstrevisionnumber:otherrevnumber filename
For example, hg diff -r 0:8 screen.css
Or the command hg log screen.css.
Use hg histgrep --all PATTERN FILENAME (used to be hg grep in the older versions, and that doesn't work anymore)
I have a legacy CVS repository which shall be migrated to Perforce.
For each module, I need to identify what branches exist in that module.
I just want a list of branch names, no tags.
It must be a command line tool, for scripting reasons.
For example (assuming there is a cvs-list-branches.sh script):
$ ./cvs-list-branches.sh module1
HEAD
dev_foobar
Release_1_2
Release_1_3
$
As a quick hack:) The same stands true for rlog.
cvs log -h | awk -F"[.:]" '/^\t/&&$(NF-1)==0{print $1}' | sort -u
Improved version as per bdevay, hiding irrelevant output and left-aligning the result:
cvs log -h 2>&1 | awk -F"[.:]" '/^\t/&&$(NF-1)==0{print $1}' | awk '{print $1}' | sort -u
You could simply parse log output of cvs log -h. For each file there will be a section named Symbolic names :. All tags listed there that have a revision number that contains a zero as the last but one digit are branches. E.g.:
$ cvs log -h
Rcs file : '/cvsroot/Module/File.pas,v'
Working file : 'File.pas'
Head revision : 1.1
Branch revision :
Locks : strict
Access :
Symbolic names :
1.1 : 'Release-1-0'
1.1.2.4 : 'Release-1-1'
1.1.0.2 : 'Maintenance-BRANCH'
Keyword substitution : 'kv'
Total revisions : 5
Selected revisions : 0
Description :
===============================================
In this example Maintenance-BRANCH is clearly a branch because its revision number is listed as 1.1.0.2. This is also sometimes called a magic branch revision number.
This will bring up tags too, but tags and branches are basically the same in CVS.
$cvs.exe rlog -h -l -b module1
I have a small collection of "handy" korn shell functions one of which fetches tags for a given file. I've made a quick attempt to adapt it to do what you want. It simply does some seding/greping of the (r)log output and lists versions which have ".0." in them (which indicates that it's a branch tag):
get_branch_tags()
{
typeset FILE_PATH=$1
TEMP_TAGS_INFO=/tmp/cvsinfo$$
/usr/local/bin/cvs rlog $FILE_PATH 1>${TEMP_TAGS_INFO} 2>/dev/null
TEMPTAGS=`sed -n '/symbolic names:/,/keyword substitution:/p' ${TEMP_TAGS_INFO} | grep "\.0\." | cut -d: -f1 | awk '{print $1}'`
TAGS=`echo $TEMPTAGS | tr ' ' '/'`
echo ${TAGS:-NONE}
rm -Rf $TEMP_TAGS_INFO 2>/dev/null 1>&2
}
with Wincvs (Gui client for windows) this is trivial, a right click will give you any branches and tags the files have.
Trough a shell you may use cvs log -h -l module.
Check for the very first file created and committed in the repository. Open the file in server which will list all the Tags and Branches together