How to avoid .git files when comparing two folders - linux

I have git installed on my Mac. I am trying to make a diff between files in two different folders.
diff -rq PATH_Folder1/ PATH_Folder2/ > Desktop/DIFF.txt
The results include .git files.
Example:
Files PATH1/abi/cpp/.git/index and PATH2/abi/cpp/.git/index differ.
How can I avoid comparing .git files. I don't require comparing git indices.

You can use the -x option to exclude file patterns. So for this case it would be:
diff -rq -x .git PATH_Folder1/ PATH_Folder2/ > Desktop/DIFF.txt

You could use git diff rather than simple diff, which should know to avoid .git files and the like. Here is the reference for the git diff command.
Even better would be using a graphical diff tool with
$ git difftool -t meld
or
$ git difftool -t kdiff3
Several guides and howtos exist out there. This is a good example.

Related

Creating a zip file of files from repo for revert purposes

My normal process for deploying to an FTP server from git is this:
git status
git add .
git commit -m "Message"
zip update.zip $(git diff --name-only HEAD^) creates a zip file.
git push origin master
The zip file that is created is a list of all the updated files with their paths.
I'd like to do something similar that creates a zip file with the same content but instead listing the files before they were changed (so the previous commit for each). This way if there is any issue with any of the files I can quickly revert the changes.
Any suggestions?
First of all, instead of your zip update.zip $(git diff --name-only HEAD^) you can use git archive --format=zip -o update.zip which won't fail if you have whitespaces in your filenames. This command also take <tree-ish> parameter which is tree or commit to produce an archive for.
I do not quite understand what you are trying to achieve, but instead your (quietly complicated) workflow I would think about using something like git-ftp.

Git delete all unmodified files

I am using git in my project at Linux platform. I have plenty of files in a particular directory. I modified some 50 above files in that directory and didn't stage and commit it. I wish to delete all other unmodified files from that directory? Is there a way to do this, using git and Linux Commands?
Not sure why you would want to do this.... but you can:
# Save changes to stash
git stash save
# Remove everything left
rm -rf ./*
# Checkout (restore) all of the changed files
git stash show --stat | grep -v changed | sed -e 's/|.*$//;' | xargs git checkout
# Restore the changes to those files
git stash pop
git reset --hard [HEAD] should work for you repeated
Repeated question How can I discard modified files?
You can also use more simple commands for this purpose:
git clean -Xfd // capital X
git clean -xfd // lower x
It will clean your working directory from the desired files.
Using git clean is what you want. To remove (-x) those files and directories (-d), run:
$ git clean -fdx
If you use the -X option instead of -x, then the files you have told git to ignore will still be kept (e.g., build artifacts). Recent versions of git require either "-f" (force) or "-n" (dry-run) to be specified.
You should run a dry-run first, to show what will happen, but not actually do anything:
$ git clean -ndx
I use this so often, that I have an alias for this (added to your .gitconfig) to check for files that would be deleted when you run git clean. It's also useful to remind me if I've forgotten to "git add" a file that I want to keep.
[alias]
# list files that would be removed via 'clean' (non-destructive)
ifc = clean -ndx
Then, running git ifc (i.e,. "ifc" = "if clean") shows everything that isn't tracked and could be removed, or isn't tracked and should be added.
https://git-scm.com/docs/git-clean

How to get diff between all files inside 2 folders that are on the web?

So I want to compare this folder http://cloudobserver.googlecode.com/svn/branches/v0.4/Boost.Extension.Tutorial/libs/boost/extension/ with this http://svn.boost.org/svn/boost/sandbox/boost/extension/. I want to get a diff file as a result. These folders are under svn control but I'd prefer git styled diff file (like one shown here) I tried git diff but it seems not to work that way for web folders. So how to do the same thing with one command on Linux?
Update:
So we had a great answer. But it works strangely - it seems to me it shows that all files (same files) have all theire contents replaced with very same contents (while I know for sure that there were only like 3-4 code lines changed at all)...
Update 2:
To achieve what I really needed (dif file with only really changed lines, with git styling, on Linux) do:
$ svn export http://cloudobserver.googlecode.com/svn/branches/v0.4/Boost.Extension.Tutorial/libs/boost/extension/ repos2 --native-eol CRLF
$ svn export http://svn.boost.org/svn/boost/sandbox/boost/extension/ repos --native-eol CRLF
$ git diff repos repos2 > fileWithReadableDiff.diff
Once you have the source trees, e.g.
diff -ENwbur repos1/ repos2/
Even better
diff -ENwbur repos1/ repos2/ | kompare -o -
and have a crack at it in a good gui tool :)
-Ewb ignore the bulk of whitespace changes
-N detect new files
-u unified
-r recurse
You urls are not in the same repository, so you can't do it with the svn diff command.
svn: 'http://svn.boost.org/svn/boost/sandbox/boost/extension' isn't in the same repository as 'http://cloudobserver.googlecode.com/svn'
Another way you could do it, is export each repos using svn export, and then use the diff command to compare the 2 directories you exported.
// Export repositories
svn export http://svn.boost.org/svn/boost/sandbox/boost/extension/ repos1
svn export http://cloudobserver.googlecode.com/svn/branches/v0.4/Boost.Extension.Tutorial/libs/boost/extension/ repos2
// Compare exported directories
diff repos1 repos2 > file.diff

svn export changes and save locally

What's the best way to export changes between 2 SVN revisions and save the changes (files/folders) locally?
Possibly through the command-line?
Thanks
How about this
svn checkout -r {2006-02-17}
http://svnbook.red-bean.com/en/1.4/svn.tour.revs.specifiers.html
esssentially you would "checkout" two folders based on dates.
EDIT: A simple folder compare at that point would give you what files changed, and what changed in the files.
EDIT2: Perhaps something along the lines of :
svn diff -r BASE:HEAD foo.c
or
svn diff -r HEAD
Not sure if you can do something like
svn diff -r BASE:HEAD
where you can update base to a number and head to a number.
My suspicion is that since this works:
svn diff -r BASE:14 foo.c
you should be able to replace base and head with numbers and just compare all the files.
I'm really not sure though.

How do you pass a file list to the linux zip command

I'm using Git for version control and unlike SVN I have not come across an inherent means of performing an export of changed files between 2 revisions, branches or tags.
As an alternative I want to use the linux zip command and pass it a set of file names, however the file names are the result of another command git diff. Below is an example of what I am trying to achieve:
zip /home/myhome/releases/files.zip git diff --name-only -a 01-tag 00-tag
However the above does not work as I guess the 'zip' command sees the git operation as part of its command options.
Does someone know how I can make something like the above work?
Thanks
You need to execute the git command in a sub-shell:
zip /home/myhome/releases/files.zip `git diff --name-only -a 01-tag 00-tag`
# another syntax (assuming bash):
zip /home/myhome/releases/files.zip $(git diff --name-only -a 01-tag 00-tag)
Another option is the xargs command:
git diff --name-only -a 01-tag 00-tag | xargs zip /home/myhome/releases/files.zip
If you're in a git shell (bash) you can also do this:
git diff -–name-only commit1 commit2 | zip ../Changes.zip –#
Works for me on Windows and Unix based systems.

Resources