How to show all the files that have been changed? - windows

I am working on a feature branch that branched off a develop branch. Now that I am ready to do a PR I just want to check which files have been changed. What git command will list all the files changed against the develop branch?

Git's diff command with the --stat option will show you a list of changed files without the detailed contents.
Use it like git diff --stat origin/develop feature_branch
If you want really basic results then you can instead use the --name-only option to just see the filenames and nothing else.

If you just want to see the file names, you can do
git diff --name-only develop

git diff develop
Often the PR tool will show you the differences too.
For example if Microsoft's Dev Ops (previously known as VSTS) when creating a pull request you can see the changes (and commits) at the bottom.

Related

How to check file/directory changes of a multi directory git repository between two git commits?

How to check file/directory changes of a multi directory git repository between two git commits?
In linux/bash we need to findout changes to a directory of multi-directory(e-store) git repository, say it has inventory-dir, order-dir, purchase-dir etc.., directories.
So basically after we do git pull we want to know in which folderes/directories files changes were made between present changes & last commit, and based on that output take an appropriate call.
We tried to use below git commands, but not sure that's the right way to proceed.
git diff inventory-dir
git log --name-status -2 inventory-dir
You might be looking for
git diff #^1
but to reduce the result to a tractable list of just file names you could add
--stat
or
--compact-summary
or merely
--name-only
Of those, my favorite is --compact-summary — it's tremendously informative while confining the output to one line per file. So then if you have a top-level directory myDirectory to which you wish to confine your attention, you would say
git diff --compact-summary #^1 -- myDirectory

Touch all files in a git repo so git thinks they are changes

I need 'touch' (I think) all files in my git repo (lots of files) so that running git status will have them as modified (and then I can add and commit them). I need to do this because our in-house tool uses the files from a git commit to generate a report ... which I've been asked to do
In posix environments I think I could just touch a directory and go from there.
I don't think that's possible because git detect that a file change if the content of the file changed. Touching the file will have no effect (even on unix).
Perhaps changing the permission on the file could be a very dirty solution but I'm not even sure of that and that's if you find a new permission that don't introduced some bad side effects!
The better solution is to update your reporting tool.
And being obliged to commit changes for ALL files to trick your tool and dirty your history is in my opinion a very bad idea...
If you were asked to "generate a report with all files" does that mean list all files in a commit? Cause that's easily done with something like a git ls-tree -R HEAD
I had a demo repo that had a bunch of files in it, that had commit messages that I didnt want showing up in the demo - and to be clear, the repo was "garbage", in that it was just basically a dump of files to demonstrate a folder structure.
That having been said, one way you could do this is to
create a new temporary folder in your repo, for example "ez"
move all the files of the repo into it, e.e. "$ mv * ez"
commit that locally, the do the reverse and move them out again
"$ mv ez/* .; rmdir ez"
That would show all files as having been changed. For my purposes, I then committed that change too, and pushed it up to my demo repo.

Programmatically overwrite a specific local file with remote file on every git pull

I have an XML file that we consider binary in git. This file is externally modified and committed.
I don't care about who edited it and what's new in the file. I just want to have the latest file version at every pull. At this time, at every git pull I have a merge conflict.
I just want that this file is overwritten on every git pull, without manually doing stuff like git fetch/checkout/reset every time I have to sync my repo.
Careful: I want to overwrite just that file, not every file.
Thanks
I thought you could use Git Hooks, but I don't see one running before a pull...
A possible workaround would be to make a script to delete this file and chain with the needed git pull...
This answer shows how to always select the local version for conflicted merges on a specific file. However, midway through the answer, the author describes also how to always use the remote version.
Essentially, you have to use git attributes to specify a specific merge driver for that specific file, with:
echo binaryfile.xml merge=keepTheirs > dir/with/binary/file/.gitattributes
git config merge.keepTheirs.name "always keep their file during merge"
git config merge.keepTheirs.driver "keepTheirs.sh %O %A %B"
git add -A
git commit -m "commit file for git attributes"
and then create keepTheirs.sh in your $PATH:
cp -f "$3" "$2"
exit 0
Please refer to that answer for a detailed explanation.
If the changes to your files are not actual changes, you should not submit them. This will clutter your version history and cause numerous problems.
From your statement I’m not quite sure which is the case, but there are 2 possibilities:
The file in question is a local storage file, the contents of which are not relevant for your actual sourcecode. In this case the file should be part of your .gitignore.
This file is actually part of your source and will thus have relevant changes in the future. By setting up the merge settings like you are planning to do, you will cause trouble once this file actually changes. Because merges will then be destructive.
In this case the solution is a little bit more complicated (apart from getting a fix for the crappy tool that changes stuff it doesn’t actually change …). What you are probably looking for is the assume unchanged functionality of git. You can access it with this command:
git update-index --assume-unchanged <file>
git docu (git help update-index):
You can set "assume unchanged" bit to
paths you have not changed to cause git not to do this check. Note that setting this bit on a path does not mean git will check the
contents of the file to see if it has changed — it makes git to omit any checking and assume it has not changed. When you make changes
to working tree files, you have to explicitly tell git about it by dropping "assume unchanged" bit, either before or after you modify
them.

extract all files changed in a git commit

I need to make a patch for someone (they are not using git) - a zip of the files changed by a commit.
I thought something like
git archive --format=zip commitguid > myfiles.zip
but this extracts the entire thing, not just the changed files. Is there any way to do this?
And to make it more complicated - is there any way of doing this with multiple commits (yes I should have branched before making the changes but that's hindsight)
EDIT
Based on #Amber solution below I can do this in 2 steps in Git Bash for windows with 7Zip installed in c:\data\progs.
git diff --name-only a-sha b-sha > tmp.txt
/C/data/progs/7za.exe a myzip.zip #tmp.txt
git diff --name-only <oldsha> <newsha> | zip dest.zip -#
filling in the proper SHAs/refs. For instance, to create a zip of only the files that changed between the master and feature branches:
git diff --name-only master feature | zip dest.zip -#
See also git help format-patch. It produces a diff patch of all changes in a commit along with commit author, date, message, and some nice diff stats. You could zip and send that.
I found this solution to the question (on github-gist, from user rmkpatchaa).
It doesn't require any external tools and is a one line command in a windows Git Bash window:
git archive --output=changes.zip HEAD $(git diff --name-only SHA1 SHA2 --diff-filter=ACMRTUXB)
It creates a standard zip archive with only the files changed between the two commits, no extra git stuff or anything, and doesn't require any extra tool on the receiving side.

Is Git checkout without merging a common file possible?

My goal involves having a file with the same name but different implementations in different branches. For example, I want to develop in a branch with verbose mode and another that works silently. Or, one branch uses a list, but the other uses a hash. Similar to prior question.
In my case, the changes are in a file with the same name. Unfortunately, checkout from one branch to the other merges the files of the same name (content?). In that case, the release version inherits the verbose print statements I had hoped to keep separate.
I learned and succeeded in using stash save; checkout; (edit other branch, add, commit); checkout back; and stash apply (to erase merge changes caused by checkout). It works, but the manual's examples (interrupted workflow, partial commits) suggest this is not the intended workflow. Creating an orphan branch for verbose destroys the history. Is there another way to switch between branches without carrying unintended changes to files with the same name?
Update I can't replicate the behavior any longer, despite seeing it five times before submitting here. It used to show the text below. But, I guess this question should be closed.
$ git checkout master
M Test.java
Switched to branch 'master'
I think the following command is what you are looking for:
git update-index --assume-unchanged <file>
To undo run:
git update-index --no-assume-unchanged <file>
From ""Difference Between 'assume-unchanged' and 'skip-worktree'", I would go with:
git update-index --skip-worktree -- a file
git update-index --no-skip-worktree -- a file
skip-worktree is useful when you instruct git not to touch a specific file ever.
That is handy for an already tracked config file.

Resources