A question I frequently ask my terminal is:
What files am I working on? (including committed files)
The answer is usually gotten by this command
git diff my_current_work_branch..master_branch | grep diff
this gives me a crude list of files that I'm currently working on.
Is there a more elegant way to get this info? All I want to ask git is,
what files does this branch add/modify/delete, relative to the master branch.
You can use git diff. If all you want is the names of files that differ, you can use the --name-only.
git diff --name-only master my_branch
or if you're actually checked out to my_branch
git diff --name-only master HEAD
or if you want to include uncommitted changes
git diff --name-only master
diffstat is a handy tool
git diff my_current_work_branch..master_branch` | diffstat -l
will show you each file that's been modified in the diff output.
Related
When using git, I have a totally new file.
git diff
will show nothing.
I need to generate the diff content for other people.
ex:
git diff > 001.patch
How to let the 001.patch contains the new file's content?
A totally new file isn't tracked, and therefore wouldn't be shown by git diff. I'd stage it by using git add ./path/to/my/new/file.txt, along with git adding any other changes you may have, and then use git diff --cached.
git diff --no-index /dev/null /path/to/your/file.txt >001.patch After applying the patch they'll have an unstaged new file though.
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.
There are about 3000 files that I need to commit to a repo. Most are images. My problem is if I do what I normally do:
git add --all
... then I can't push because the git server has various limits that it just keeps hitting. I tried adding workarounds for these limits, but the truth is, I don't normally do such big commits, so I would prefer to not change the settings.
Instead I was hoping there is a way to ONLY add the first 100 untracked files and then stop. Then I can do a "git commit" and a "git push" and all should be well with the world.
Any idea how to do this?
If you have bash available, this should work: list all untracked files, select the first 100 to pass to git add as argument.
git ls-files --others --exclude-standard | head -n 100 | xargs git add
git revert HEAD reverts all changes, but what I want to revert the ones except my go extension files? I want to revert all changes except the one with *.go
I tried
git revert HEAD ^*.go
git revert HEAD *.go?
None of them works. Where should I look up to find this feature?
Thanks~!
There may be a better way, but what should work:
git revert --no-commit HEAD
git reset HEAD -- *.go
git checkout -- *.go`
git commit
Or you can approach it the other way around and instead of using revert, checkout the files you want to revert from the old commit:
git checkout <commit> -- <paths to revert>
git commit
I am by no means an expert with piping output into Git commands, but you could try something along the lines of:
git checkout HEAD^ -- $(find. -not -path '*.git*' -not -iname '*.go' -type f)
The find output should consist of all the files that do not have the go extension. These files will then be reverted to their state in the last HEAD. You may need to add additional -not chunks for folders or files you want to ignore.
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.