date int64 1,220B 1,719B | question_description stringlengths 28 29.9k | accepted_answer stringlengths 12 26.4k | question_title stringlengths 14 159 |
|---|---|---|---|
1,331,066,898,000 |
I'm trying to do a git clone trough a bash script, but the first time that I run the script and the server is not known yet the script fails. I have something like this:
yes | git clone [email protected]:repo/repoo.git
The authenticity of host 'github.com (207.97.227.239)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)?
But it's ignoring the yes. Do you know how to force git clone to add the key to the known hosts?
|
Add the following to your ~/.ssh/config file:
Host github.com
StrictHostKeyChecking no
Anything using the open-ssh client to establish a remote shell (with the git client does) should skip the key checks to github.com.
This is actually a bad idea since any form of skipping the checks (whether you automatically hit yes or skip the check in the first place) creates room for a man in the middle security compromise. A better way would be to retrieve and validate the fingerprint and store it in the known_hosts file before needing to run some script that automatically connects.
| Answer yes in a bash script |
1,331,066,898,000 |
We all know that Linus Torvalds created Git because of issues with Bitkeeper. What is not known (at least to me) is, how were issues/tickets/bugs tracked up until then? I tried but didn't get anything interesting. The only discussion I was able to get on the subject was this one where Linus shared concerns with about using Bugzilla.
Speculation: - The easiest way for people to track bugs in the initial phase would have been to put tickets in a branch of its own but am sure that pretty quickly that wouldn't have scaled with the noise over-taking the good bugs.
I've seen and used Bugzilla and unless you know the right 'keywords' at times you would be stumped. NOTE: I'm specifically interested in the early years (1991-1995) as to how they used to track issues.
I did look at two threads, "Kernel SCM saga", and "Trivia: When did git self-host?" but none of these made mention about bug-tracking of the kernel in the early days.
I searched around and wasn't able to get of any FOSS bug-tracking software which was there in 1991-1992. Bugzilla, Request-tracker, and others came much later, so they appear to be out.
Key questions
How did then Linus, the subsystem-maintainers, and users report and track bugs in those days?
Did they use some bug-tracking software, made a branch of bugs and manually committed questions and discussions on the bug therein (would be expensive and painful to do that) or just use e-mail.
Much later, Bugzilla came along (first release 1998) and that seems to be the primary way to report bugs afterwards.
Looking forward to have a clearer picture of how things were done in the older days.
|
In the beginning, if you had something to contribute (a patch or a bug report), you mailed it to Linus. This evolved into mailing it to the list (which was [email protected] before kernel.org was created).
There was no version control. From time to time, Linus put a tarball on the FTP server. This was the equivalent of a "tag". The available tools at the beginning were RCS and CVS, and Linus hates those, so everybody just mailed patches. (There is an explanation from Linus about why he didn't want to use CVS.)
There were other pre-Bitkeeper proprietary version control systems, but the decentralized, volunteer-based development of Linux made it impossible to use them. A random person who just found a bug will never send a patch if it has to go through a proprietary version control system with licenses starting in the thousands of dollars.
Bitkeeper got around both of those problems: it wasn't centralized like CVS, and while it was not Free Software, kernel contributors were allowed to use it without paying. That made it good enough for a while.
Even with today's git-based development, the mailing lists are still where the action is. When you want to contribute something, you'll prepare it with git of course, but you'll have to discuss it on the relevant mailing list before it gets merged. Bugzilla is there to look "professional" and soak up half-baked bug reports from people who don't really want to get involved.
To see some of the old bug-reporting instructions, get the historical Linux repository. (This is a git repository containing all the versions from before git existed; mostly it contains one commit per release since it was reconstructed from the tarballs). Files of interest include README, MAINTAINERS, and REPORTING-BUGS.
One of the interesting things you can find there is this from the Linux-0.99.12 README:
- if you have problems that seem to be due to kernel bugs, please mail
them to me ([email protected]), and possibly to any other
relevant mailing-list or to the newsgroup. The mailing-lists are
useful especially for SCSI and NETworking problems, as I can't test
either of those personally anyway.
| How did the Linux Kernel project track bugs in the Early Days? |
1,331,066,898,000 |
Assume I have some issue that was fixed by a recent patch to the official Linux git repository. I have a work around, but I’d like to undo it when a release happens that contains my the fix. I know the exact git commit hash, e.g. f3a1ef9cee4812e2d08c855eb373f0d83433e34c.
What is the easiest way to answer the question: What kernel releases so far contain this patch? Bonus points if no local Linux git repository is needed.
(LWM discusses some ideas, but these do require a local repository.)
|
In GitHub kernel repository, you can check all tags/kernel versions.
Example for dc0827c128c0ee5a58b822b99d662b59f4b8e970 provided by Jim Paris:
If three-dots are clicked, full list of tags/kernel versions can be seen.
| Given a git commit hash, how to find out which kernel release contains it? |
1,331,066,898,000 |
Most of my my aliases are of this form: alias p='pwd'
I want to alias git commit so that it does git commit -v
But trying to create an alias with a space gives an error:
$ alias 'git commit'='git commit -v'
-bash: alias: `git commit': invalid alias name
|
Not a direct answer to your question (since aliases can only be one word), but you should be using git-config instead:
git config --global alias.civ commit -v
This creates a git alias so that git civ runs git commit -v. Unfortunately, AFAIK there is no way to override existing git commands with aliases. However, you can always pick a suitable alias name to live with as an alternative.
| How can I create an alias for a git [action] command (which includes spaces)? |
1,331,066,898,000 |
Is there a way to identify with a username and password to github.com servers for the purpose of adding an ssh key to the github user account? So far everything I've read suggests that a user's ssh key must be added via the web GUI. I'm looking for the method or process of adding a key via a command line interface or else a bash/ansible/something script.
|
Update 2020
As stated in developer changes, Password authentication is going to be deprecated at:
November 13, 2020 at 16:00 UTC
Additionally, as @trysis asked in the comments, we need a solution for 2FA.
The new way is to use a personal access token:
For our specific example (adding a ssh key), we only need write permissions (read permissions are added automatically on using write permissions):
The updated command (via curl):
curl -H "Authorization: token YourGeneratedToken" --data '{"title":"test-key","key":"ssh-rsa AAA..."}' https://api.github.com/user/keys
This does also work when 2FA is enabled.
OLD
Auth with username and password is supported by github api:
There are three ways to authenticate through GitHub API v3.
...
Basic Authentication
$ curl -u "username" https://api.github.com
...
So just choose a lib in the language you prefer
and use the implemented version of the Create a Public Key "Public Key" API Section:
Creates a public key. Requires that you are authenticated via Basic Auth, or OAuth with at least [write:public_key] scope.
INPUT
POST /user/keys
{
"title": "octocat@octomac",
"key": "ssh-rsa AAA..."
}
If you want to use it from command line (via curl):
curl -u "username" --data '{"title":"test-key","key":"ssh-rsa AAA..."}' https://api.github.com/user/keys
or even without prompting for password:
curl -u "username:password" --data '{"title":"test-key","key":"ssh-rsa AAA..."}' https://api.github.com/user/keys
here is a nice little tutorial for using curl to interact with github API
| command line method or programmatically add ssh key to github.com user account |
1,331,066,898,000 |
I have find command that display files in my project:
find . -type f -not -path './node_modules*' -a -not -path '*.git*' \
-a -not -path './coverage*' -a -not -path './bower_components*' \
-a -not -name '*~'
How can I filter the files so it don't show the ones that are in .gitignore?
I thought that I use:
while read file; do
grep $file .gitignore > /dev/null && echo $file;
done
but .gitignore file can have glob patterns (also it will not work with paths if file is in .gitignore), How can I filter files based on patterns that may have globs?
|
git provides git-check-ignore to check whether a file is excluded by .gitignore.
So you could use:
find . -type f -not -path './node_modules*' \
-a -not -path '*.git*' \
-a -not -path './coverage*' \
-a -not -path './bower_components*' \
-a -not -name '*~' \
-exec sh -c '
for f do
git check-ignore -q "$f" ||
printf '%s\n' "$f"
done
' find-sh {} +
Note that you would pay big cost for this because the check was performed for each file.
| Find files that are not in .gitignore |
1,331,066,898,000 |
I don't subscribe to the linux-kernel mailing list, but I want to get a set of patches that were posted a few weeks ago and apply them to my kernel for testing. I'm very familiar with patching, building, etc. My question is, what's the best way to get a copy of this patch set? It's not applied to any Git repo that I'm aware of, it's just been posted to the mailing list for discussion.
I find a number of sites that archive the linux-kernel mailing list and I can see the set of patches there, but none of these sites have any method (that I can find) of downloading the raw email so I can use "git apply" or "patch" or whatever. Just copy/pasting the content from my web browser seems like it will not be very successful due to whitespace differences etc.
How do people manage this?
|
http://marc.info/ has a link for each message to get the raw body, and https://lkml.org/ has (in the sidebar) links to download any contained diffs.
There are also archives with NNTP access that may provide raw messages, though I haven't tried this.
| How do I get a linux kernel patch set from the mailing list? |
1,331,066,898,000 |
The other day I tried installing opencv-git from the AUR with makepkg on Arch Linux. Of course it pulls from the git repository as the name indicates. This pulls 1Gb. I am reading about making a shallow clone with git. When I look at the PKGBUILD file, using grep git PKGBUILD, I see:
pkgname="opencv-git"
makedepends=('git' 'cmake' 'python2-numpy' 'mesa' 'eigen2')
provides=("${pkgname%-git}")
conflicts=("${pkgname%-git}")
source=("${pkgname%-git}::git+http://github.com/Itseez/opencv.git"
cd "${srcdir}/${pkgname%-git}"
git describe --long | sed -r 's/([^-]*-g)/r\1/;s/-/./g'
cd "${srcdir}/${pkgname%-git}"
cd "${srcdir}/${pkgname%-git}"
cd "${srcdir}/${pkgname%-git}"
install -Dm644 "LICENSE" "${pkgdir}/usr/share/licenses/${pkgname%-git}/LICENSE"
Is there a way to modify the recipe or the makepkg command to pull only a shallow clone (the latest version of the source is what I want) and not the full repository to save space and bandwidth? Reading man 5 PKGBUILD doesn't provide the insight I'm looking for. Also looked quickly through the makepkg and pacman manpages - can't seem to find how to do that.
|
This can be done by using a custom dlagent. I do not really understand Arch packaging or how the dlagents work, so I only have a hack answer, but it gets the job done.
The idea is to modify the PKGBUILD to use a custom download agent. I modified the source
"${pkgname%-git}::git+http://github.com/Itseez/opencv.git"
into
"${pkgname%-git}::mygit://opencv.git"
and then defined a new dlagent called mygit which does a shallow clone by
makepkg DLAGENTS='mygit::/usr/bin/git clone --depth 1 http://github.com/Itseez/opencv.git'
Also notice that the repository that is being cloned is hard-coded into the command. Again, this can probably be avoided. Finally, the download location is not what the PKGBUILD expects. To work around this, I simply move the repository after downloading it. I do this by adding
mv "${srcdir}/../mygit:/opencv.git" "${srcdir}/../${pkgname%-git}"
at the beginning of the pkgver function.
I think the cleaner solution would be to figure out what the git+http dlagent is doing and redfine that temporarily. This should avoid all the hack aspects of the solution.
| How to modify a PKGBUILD which uses git sources to pull only a shallow clone? |
1,331,066,898,000 |
So I have a git repository that I cloned from an upstream source on github. I made a few changes to it (that are uncommitted in the master branch). What I want to do is push my changes onto my github page as a new branch and have github still see it as a fork.
Is that possible? I'm fairly new to git and github. Did my question even make sense?
The easiest way that I can think of (which I'm sure is the most aroundabout way), is to fork the repo on github. Clone it locally to a different directory. Add the upstream origin repo. Create a branch in that new forked repo. Copy my code changes by hand into the new local repo. And then push it back up to my github.
Is this a common use case that there's a simpler way of doing it without duplicating directories?
I guess I'm asking here as opposed to SO since I'm on linux using command line git and the people here give better answers imo =]
|
You can do it all from your existing repository (no need to clone the fork into a new (local) repository, create your branch, copy your commits/changes, etc.).
Get your commits ready to be published.
Refine any existing local commits (e.g. with git commit --amend and/or git rebase --interactive).
Commit any of your uncommitted changes that you want to publish (I am not sure if you meant to imply that you have some commits on your local master and some uncommitted changes, or just some uncommitted changes; incidentally, uncommitted changes are not “on a branch”, they are strictly in your working tree).
Rename your master branch to give it the name you want for your “new branch”. This is not strictly necessary (you can push from any branch to any other branch), but it will probably reduce confusion in the long run if your local branch and the branch in your GitHub fork have the same name.
git branch -m master my-feature
Fork the upstream GitHub repository
(e.g.) github.com:UpstreamOwner/repostory_name.git as
(e.g.) github.com:YourUser/repository_name.git.
This is done on the GitHub website (or a “client” that uses the GitHub APIs), there are no local Git commands involved.
In your local repository (the one that was originally cloned from the upstream GitHub repository and has your changes in its master), add your fork repository as a remote:
git remote add -f github github.com:YourUser/repository_name.git
Push your branch to your fork repository on GitHub.
git push github my-feature
Optionally, rename the remotes so that your fork is known as “origin” and the upstream as “upstream”.
git remote rename origin upstream
git remote rename github origin
One reason to rename the remotes would be because you want to be able to use git push without specifying a repository (it defaults to “origin”).
| Github adding a repository as a fork from an existing clone |
1,331,066,898,000 |
I'm syncing ~/.gitconfig and ~/.gitignore files in ubuntu and Mac by using dropbox and created symlink for it.
And excludesfile is declared like this.
[core]
editor = /usr/bin/vim
excludesfile = /Users/username/.gitignore
The problem is home directory differs by os, therefore I need multiple setting for excludesfile.
Is it possible to define multiple core.excludesfile?
|
You can only have a single core.excludesfile; the last setting is the one that's used. However, you don't need multiple files: git supports ~ as an abbreviation for your home directory.
[core]
excludesfile = ~/.gitignore
In general, if you really needed to have multiple excludes files, the simplest solution would be to generate a single file that's the concatenation of the others, and update it whenever one of the files changes.
| How to set multiple `core.excludesfile` in `.gitconfig`? |
1,331,066,898,000 |
I am thinking on a system, where /etc were tracked on a remote git repository. I am thinking on a git workflow, where every host machine where a different branch.
Every previous versions on every machine could be easily tracked, compared, merged.
If a /etc modification had to be committed on many machines, it could be easily done by some merging script.
In case of an "unwanted" /etc change, this could be good visible (even alarm scripts could be tuned to watch that).
Anybody used already a such configuration? Are there any security problems with it?
|
The program etckeeper does manage /etc in git, you just need to change the default vcs backend from bzr to git in /etc/etckeeper/etckeeper.conf.
It is installed by default in Ubuntu Linux, and handles the common cases of when to commit automatically.
It commits before installing packages in case there are uncomitted manual changes, and after installing.
| Using git to manage /etc? |
1,331,066,898,000 |
git log -G<regex> -p is a wonderful tool to search a codebase's history for changes that match the specified pattern. However, it can be overwhelming to locate the relevant hunk in the diff/patch output in a sea of mostly irrelevant hunks.
It’s of course possible to search the output of git log for the original string/regex, but that does little to reduce the visual noise and distraction of many unrelated changes.
Reading up on git log, I see there's the --pickaxe-all, which is the exact opposite of what I want: it broadens the output (to the entire changeset), whereas I want to limit it (to the specific hunk).
Essentially, I’m looking for a way to "intelligently" parse the diff/patch into individual hunks and then execute a search against each hunk (targeting just the changed lines), discard the hunks that don’t match, and output the ones that do.
Does a tool such as I describe exist? Is there a better approach to get the matched/affected hunks?
Some initial research I've done...
If it were possible to grep the diff/patch output and make the context option values dynamic—say, via regexps instead of line counts—that might suffice. But grep isn't exactly built that way (nor am I necessarily requesting that feature).
I found the patchutils suite, which initially sounded like it might suit my needs. But after reading its man pages, the tools doesn't appear to handle matching hunks based on regexps. (They can accept a list of hunks, though...)
I finally came across splitpatch.rb, which seems to handle the parsing of the patch well, but it would need to be significantly augmented to handle reading patches via stdin, matching desired hunks, and then outputting the hunks.
|
here https://stackoverflow.com/a/35434714/5305907 is described a way to do what you are looking for. effectively:
git diff -U1 | grepdiff 'console' --output-matching=hunk
It shows only the hunks that match with the given string "console".
| Display only relevant hunks of a diff/patch based on a regexp |
1,331,066,898,000 |
Git seems to support configuration values at three levels:
Per-system global settings (stored in /etc/git-core)
Per-user global settings (stored in ~/.gitconfig)
Per-repository local settings (stored in $REPO/.git/config)
These options cover most of the basis but I'm looking for a way to handle a fourth level. I have a (very) large collection of repositories for which I need to use a different value for user.email than my usual. These repositories are often created and manipulated through automated scripts, and setting up per repository local settings is cumbersome.
All of the repositories in question are located under a certain path prefix on my local system. Is there a way to set a configuration value somewhere that will be inherited by all repositories under that path? (Sort of like .htaccess settings inherit all the way up the file system.) Perhaps there would be a way to set conditional values in the global config file? What other arrangements could be made in a UNIX environment to cope with a set of repositories like mine?
|
I have found no way to configure git at this fourth level. The only way seems to be per-command configuration value overrides using git -c key=value.
My current hacky solution is to define a shell function that serves as a wrapper for git. When called, it passes the arguments onto the system git command, but not before checking on the present working directory and adding an extra argument to the command if applicable.
function git () {
case "$PWD" in
/path/to/repos/*)
command git -c [email protected] "$@"
;;
*)
command git "$@"
;;
esac
}
| Can git configuration be set across multiple repositories? |
1,331,066,898,000 |
I created ssh key. I use it to connect with git repositories. When creating the key, I noticed the prompt that said the password should be hard to guess. Therefore, I came up with 40+ characters-long password. Now, every time I do git clone, push or anything similar, I need to input the password(which takes some time, especially when I don't get it right).
I certainly am glad that I'm enjoying security features; however, I'd prefer for ssh password to cache for 5-15 minutes(or any other arbitrary amount); sometimes I do many operations on repository in small time frame, and typing password is taking too much time. How can I do this?
|
You can do this using an SSH agent. Most desktop environments start one for you; you can add your key to it by running
ssh-add
If you need to start the agent, run
eval $(ssh-agent)
(this sets up a number of environment variables).
The -t option to ssh-agent will allow you to specify the timeout. See Configuring the default timeout for the SSH agent for more details.
| Remember password for ssh key for some time |
1,331,066,898,000 |
Git completion:
I'm having difficulty with git's filename autocompletions on my system. I'm using zsh (5.0.5) with git (1.9.3) on OS X (10.9.3). Both zsh and git have been installed via homebrew. (Full version output are at the bottom of the post.)
git's filename completion isn't inserting spaces like I expect. When I type the name of a file with a space in the name, the shell inserts the filename without spaces escaped. zsh's built-in completion doesn't do this, but git's does.
Here's an example of what I'm seeing.
I have a repository with a few files with spaces in their names.
% ls -la
test
test four - latest.txt
test three.txt
test two
The shell backslash escapes the filenames as expected when I use tab completion to insert the file name.
% echo "testing" >> test<tab>
autocompletes to this after hitting tab three times.
% echo "testing" >> test\ four\ -\ latest.txt
––– file
test test\ four\ -\ latest.txt test\ three.txt test\ two
git status shows these filenames in quotes (it totally understands what's up):
% git status --short
M test
M "test four - latest.txt"
M "test three.txt"
M "test two"
but when I try to git add with tab autocompletion, it goes sideways.
% git add test<tab>
results in this after hitting tab three times:
% git add test four - latest.txt
test test four - latest.txt test three.txt test two
I've tried regressing this a bit: my dotfiles are in version control, so I've tried zsh 4.3.15, git 1.8.3, and my dotfiles from a year ago, when I'm nearly certain this worked. Weirdly, this setup was still broken.
I have narrowed it down to the _git completion file that is being sourced from /usr/local/share/zsh/site-functions:
% echo $FPATH
/usr/local/share/zsh/site-functions:/usr/local/Cellar/zsh/5.0.5/share/zsh/functions
% ls -l /usr/local/share/zsh/site-functions
_git@ -> ../../../Cellar/git/1.9.3/share/zsh/site-functions/_git
_hg@ -> ../../../Cellar/mercurial/3.0/share/zsh/site-functions/_hg
_j@ -> ../../../Cellar/autojump/21.7.1/share/zsh/site-functions/_j
git-completion.bash@ -> ../../../Cellar/git/1.9.3/share/zsh/site-functions/git-completion.bash
go@ -> ../../../Cellar/go/HEAD/share/zsh/site-functions/go
If I manually change $FPATH before my .zshrc runs compinit (or simply remove the /usr/local/share/zsh/site-functions/_git symbolic link), then completions fall back to zsh and work as expected.
The zsh completion without _git:
% git add test<tab>
hitting tab three times produces correct results:
% git add test\ four\ -\ latest.txt
––– modified file
test test\ four\ -\ latest.txt test\ three.txt test\ two
Side note: I've tried removing the git-completion.bash link, and it just totally breaks things:
% git add test<tab>
produces this busted-ness:
% git add test__git_zsh_bash_func:9: command not found: __git_aliased_command
git add test
––– file
test test\ four\ -\ latest.txt test\ three.txt test\ two
I really want to get this working properly: the rest of the _git completions were great because they're more repo-aware than the zsh ones, but I need filenames with spaces or other special characters to be properly escaped.
Software versions:
% zsh --version
zsh 5.0.5 (x86_64-apple-darwin13.0.0)
% git --version
git version 1.9.3
% sw_vers
ProductName: Mac OS X
ProductVersion: 10.9.3
BuildVersion: 13D65
I've uploaded the _git and git-completion.bash files: git-completion.bash and _git (renamed to _git.sh so CloudApp will make it viewable in the browser.)
|
This bug is mentioned on the mailing list.
The fix is to edit the file git-completion.zsh and remove the -Q option from compadd, in in __gitcomp_file.
--- i/contrib/completion/git-completion.zsh
+++ w/contrib/completion/git-completion.zsh
@@ -90,7 +90,7 @@ __gitcomp_file ()
local IFS=$'\n'
compset -P '*[=:]'
- compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
+ compadd -p "${2-}" -f -- ${=1} && _ret=0
}
__git_zsh_bash_func ()
This file is installed from the contrib/completion directory, and its path may vary with your package manager. If you installed with homebrew on macOS, it's located in /usr/local/Cellar/git/2.10.2/share/zsh/site-functions.
| git completion with zsh: filenames with spaces aren't being escaped properly |
1,331,066,898,000 |
I'm trying to get watch to display colors from 'git status'.
I've tried running watch with the --color option, as suggested elsewhere here, but, still, watch --color 'git status' doesn't display colors.
|
When git status is run under watch, it is able to detect that its standard output is not a terminal, meaning it will not output colors if the color.status setting is set to auto. To force git status to always output colors (even under watch), set color.stats to always, e.g.
git config color.status always
to set the setting permanently, or as @ChrisJonsen points out, use git -c color.status=always status to run git status with a one-time override.
| watch command not showing colors for 'git status' |
1,409,919,431,000 |
less itself isn't capable of doing syntax highlighting, according to this thread.
However, git diff nicely shows colored output in less, its default pager. When I redirect the output of git diff into a file, no color escape sequences are visible.
Does git diff know where it's being sent, and formats the output accordingly? How would one do that?
I just noticed that git colors the diff output (e.g. git diff), however, it doesn't know how to syntax highlighting in general. e.g.
git show 415fec6:log.tex
doesn't enable any TeX-like syntax.
Reading the git sources, I found the following hints
in diff.h:
int use_color;
I was previously referring to syntax highlighting, but that was not correct. What I mean is output coloring, see e.g.
|
Git uses isatty() to check whether stdout is a tty: this is used to see if a pager must be used (pager.c) as well as colors (color.c).
| Git pager is less, but what is causing the output coloring? |
1,409,919,431,000 |
Naive approach is find dir1 dir2 dir3 -type d -name .git | xargs -I {} dirname {}
, but it's too slow for me, because I have a lot deep folder structures inside git repositories (at least I think that this is the reason). I've read about that I can use prune to prevent find to recurse into directories once it found something, but there's two things. I'm not sure how this works (I mean I don't understand what prune does although I've read man page) and the second it wouldn't work in my case, because it would prevent find to recurse into .git folder but not into all other folders.
So what I actually need is:
for all subdirectories check if they contain a .git folder and if it is then stop searching in this filesystem branch and report result. It would be perfect if this would also exclude any hidden directories from search.
|
Ideally, you'd want to crawl directory trees for directories that contain a .git entry and stop searching further down those (assuming you don't have further git repos inside git repos).
The problem is that with standard find, doing this kind of check (that a directory contains a .git entry) involves spawning a process that executes a test utility using the -exec predicate, which is going to be less efficient than listing the content of a few directories.
An exception would be if you use the find builtin of the bosh shell (a POSIXified fork of the Bourne shell developed by @schily) which has a -call predicate to evaluate code in the shell without having to spawn a new sh interpreter:
#! /path/to/bosh -
find . -name '.?*' -prune -o \
-type d -call '[ -e "$1/.git" ]' {} \; -prune -print
Or use perl's File::Find:
perl -MFile::Find -le '
sub wanted {
if (/^\../) {$File::Find::prune = 1; return}
if (-d && -e "$_/.git") {
print $File::Find::name; $File::Find::prune = 1
}
}; find \&wanted, @ARGV' .
Longer, but faster than zsh's printf '%s\n' **/.git(:h) (which descends into all non-hidden directories), or GNU find's find . -name '.?*' -prune -o -type d -exec test -e '{}/.git' \; -prune -print which runs one test command in a new process for each non-hidden directory.
2022 edit. The find applet from recent versions of busybox is able to run its [ or test applet without having to fork a process and reexecute itself inside, so, even though it's still not as fast as the bosh or perl approaches:
busybox find . -type d -exec [ -e '{}/.git' ] ';' -prune -print
In my test is several orders of magnitude faster than the GNU find equivalent (on a local sample containing a mix of git / cvs / svn repositories with over 100000 directories in total, I get 0.25s for bosh, 0.3s for perl 0.7s for busybox find, 36s for GNU find, 2s for GNU find . -name .git -printf '%h\n' (giving a different result as it also finds .git files in subdirs of git repositories)).
| How to find all git repositories within given folders (fast) |
1,409,919,431,000 |
I use etckeeper for changes in my configfiles (on Debian squeeze)
Since I also have an ircdeamon running, there are some files, that change every minute in the folder
/etc/hybserv/
I don't want to version control them anymore, so I added
hybserv/*
to the end of
/etc/.gitignore
but they are not ignored! They keep showing up every hour in the hourly commit.
What am I doing wrong?
|
You need to delete (=unregister) them from git.
Use something like
cd /etc
git rm --cached hybserv/*
git commit -m "Remove hybserv/* files from git"
Note the --cached option. With it, the files are only removed from git and are not deleted from the disk.
| Excluding files in etckeeper with .gitignore doesn't work |
1,409,919,431,000 |
I am trying to get a bash array of all the unstaged modifications of files in a directory (using Git). The following code works to print out all the modified files in a directory:
git -C $dir/.. status --porcelain | grep "^.\w" | cut -c 4-
This prints
"Directory Name/File B.txt"
"File A.txt"
I tried using
arr1=($(git status --porcelain | grep "^.\w" | cut -c 4-))
but then
for a in "${arr1[@]}"; do echo "$a"; done
(both with and without the quotes around ${arr1[@]} prints
"Directory
Name/File
B.txt"
"File
A.txt"
I also tried
git -C $dir/.. status --porcelain | grep "^.\w" | cut -c 4- | readarray arr2
but then
for a in "${arr2[@]}"; do echo "$a"; done
(both with and without the quotes around ${arr2[@]}) prints nothing. Using declare -a arr2 beforehand does absolutely nothing either.
My question is this: How can I read in these values into an array? (This is being used for my argos plugin gitbar, in case it matters, so you can see all my code).
|
TL;DR
In bash:
readarray -t arr2 < <(git … )
printf '%s\n' "${arr2[@]}"
There are two distinct problems on your question
Shell splitting.
When you did:
arr1=($(git … ))
the "command expansion" is unquoted, and so: it is subject to shell split and glob.
The exactly see what that shell splitting do, use printf:
$ printf '<%s> ' $(echo word '"one simple sentence"')
<word> <"one> <simple> <sentence">
That would be avoided by quoting:
$ printf '<%s> ' "$(echo word '"one simple sentence"')"
<word "one simple sentence">
But that, also, would avoid the splitting on newlines that you want.
Pipe
When you executed:
git … | … | … | readarray arr2
The array variable arr2 got set but it went away when the pipe (|) was closed.
You could use the value if you stay inside the last subshell:
$ printf '%s\n' "First value." "Second value." |
{ readarray -t arr2; printf '%s\n' "${arr2[@]}"; }
First value.
Second value.
But the value of arr2 will not survive out of the pipe.
Solution(s)
You need to use read to split on newlines but not with a pipe.
From older to newer:
Loop.
For old shells without arrays (using positional arguments, the only quasi-array):
set --
while IFS='' read -r value; do
set -- "$@" "$value"
done <<-EOT
$(printf '%s\n' "First value." "Second value.")
EOT
printf '%s\n' "$@"
To set an array (ksh, zsh, bash)
i=0; arr1=()
while IFS='' read -r value; do
arr1+=("$value")
done <<-EOT
$(printf '%s\n' "First value." "Second value.")
EOT
printf '%s\n' "${arr1[@]}"
Here-string
Instead of the here document (<<) we can use a here-string (<<<):
i=0; arr1=()
while IFS='' read -r value; do
arr1+=("$value")
done <<<"$(printf '%s\n' "First value." "Second value.")"
printf '%s\n' "${arr1[@]}"
Process substitution
In shells that support it (ksh, zsh, bash) you can use <( … ) to replace the here-string:
i=0; arr1=()
while IFS='' read -r value; do
arr1+=("$value")
done < <(printf '%s\n' "First value." "Second value.")
printf '%s\n' "${arr1[@]}"
With differences: <( ) is able to emit NUL bytes while a here-string might remove (or emit a warning) the NULs. A here-string adds a trailing newline by default. There may be others AFAIK.
readarray
Use readarray in bash[a] (a.k.a mapfile) to avoid the loop:
readarray -t arr2 < <(printf '%s\n' "First value." "Second value.")
printf '%s\n' "${arr2[@]}"
[a]In ksh you will need to use read -A, which clears the variable before use, but needs some "magic" to split on newlines and read the whole input at once.
IFS=$'\n' read -d '' -A arr2 < <(printf '%s\n' "First value." "Second value.")
You will need to load a mapfile module in zsh to do something similar.
| Read lines into array, one element per line using bash |
1,409,919,431,000 |
I work with LaTeX and do versioning with Git. For bibliography management I use Mendeley.
The problem is that each time Mendeley synchronizes it's .bib exports,
they are in different order, what makes bibliography versioning much harder.
My idea is to sort BibTex entries in .bib file, each time before commit.
Could you help me, how to do this in smart (short&sweet) way ? :)
P.S. I can run this routine manually. I do not need git integration. I just want program/script to sort .bib file.
|
How about bibsort?
NAME
bibsort - sort a BibTeX bibliography file
SYNOPSIS
bibsort [optional sort(1) switches] < infile >outfile
DESCRIPTION
bibsort filters a BibTeX bibliography, or bibliography frag-
ment, on its standard input, printing on standard output a
sorted bibliography.
It's a shell script wrapping nawk (and tr, sort and grep) and includes two warnings you might have to pay attention to (see the source).
(Edit There're also a lot of bibtex-related Perl modules...)
Edit2 I just recognized you'd like to sort for any key, while bibsort apparently sorts by the bibtex tags only -- but maybe its source (it's not too long) is still helpful...?
| How to sort (by whatever key) BibTex entries in `.bib` file? |
1,409,919,431,000 |
Normally diff and git diff show both the original and the modified line with - and + respectively. Is there any way, I can filter only to see the modified line? This would reduce the number of lines to read by a factor of 2 instantly.
I was assuming
git diff test.yml | grep '^+' | less -R
and
git diff test.yml | egrep '^+' | less -R
to have the same result. ie they would show any new additions in a file. However egrep shows me the entire file. Why is that so?
With the above method anyways, I lose the color. Is there any way to retain the color?
|
You can use --word-diff to condense the + and - lines together with the changes highlighted using red/green text and stop using grep all together.
You can combine this with -U0 to remove all context around the diffs if you really want to condense it down further.
This approch is better than using grep as you don't lose output, you can tell when a line was added or simply changed and you don't completely lose removals while still condensing the output down into something that is easy to read.
The answer to the question regarding egrep is already answered by @Stephen Kitt here
| diff to show only the additions in a changed file |
1,409,919,431,000 |
Possible Duplicate:
What does “--” (double-dash) mean?
git diff [options] [<commit>] [--] [<path>…]
In here, how should I understand what [--] means? And when should I use it.
|
As always, you should read a command's manpage to find out how it interprets its arguments.
-- is commonly used to indicate the end of the command options. This is especially useful if you want to pass a filename or other argument that begins with -. It's also a good idea to use it before wildcards that might expand to a filename beginning with a hyphen. (For example, try mkdir foo; cd foo; echo >-l; ls *; ls -- *.)
But git diff also uses it to indicate whether an argument is a <commit> (indicating what revision to diff) or a <path> (indicating which file to diff). It can usually guess, but it's possible for a value to be both a valid commit and a valid path. In that case, you can use git diff foo -- to indicate that foo is a commit, or git diff -- foo to indicate that foo is a path.
| What does "--" mean in Linux/Unix command line? [duplicate] |
1,409,919,431,000 |
I get the following error when accessing Github over HTTPS:
error: server certificate verification failed.
CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none
This is because I don't have any certificates in /etc/ssl/certs/. I know how to fix this problem. I can install the package ca-certificates from Debian repository. The problem is, however, that this will install all certificates (thousands) which I don't necessarily want to accept/trust.
How can I install certificate for Github only?
a Subproblem/Subquestion
On another machine, where the package ca-certificates is already installed and git works, I have noticed that some certificates in /etc/ssl/certs/ are one-certificate-per-file and other are many-certificates-in-one-file. The particular file containing Github certificate, /etc/ssl/certs/ca-certificates.crt contains over 150 other certificates:
$ grep 'BEGIN CERTIFICATE' /etc/ssl/certs/ca-certificates.crt | wc -l
159
How can I find which one out of these 159 certificate is the one I need? (other than brute force - slicing the file in halves and checking both halves, repeating while n > 1).
|
In order to access your Github you need to do it via ssh. So you need to add your ssh public key to github. After that you are able to access github via ssh i.e.:
git init [email protected]:yourname/yourrepo.git
See also: Github: generating ssh keys, WikiHow
[Edit #1]
without certificate checks:
GIT_SSL_NO_VERIFY=true git clone https://github.com/p/repo.git
or authenticated
GIT_SSL_NO_VERIFY=true git clone https://user@pass:github.com/p/repo.git
For me it is still not clear what are you asking for, because you know that installing ca-certificates will fix the problem.
[Edit #2]
Ok, the other question was
how to have only the certificate which is needed to access github.com via https
Open your browser and navigate to https://github.com/.
Klick on the green name on the left from https:// and klick on
Certificates. On the Details tab, you'll see the
certificate chain, which is:
DigiCert ...
DigiCert ...
github.com ...
Export each of the DigiCert certicates to a file.
copy the files to /etc/ssl/certs/
run c_rehash which cat all certificates to ca-certificates.crt
you are done.
As I said, I am not a friend of such actions because github can change the CA's anytime,
so it will always result in additional work.
| adding SSL certificate for Github only (not all certificates from ca-certificates package) |
1,409,919,431,000 |
I'm tweaking the pager of Git, but I've got some issues with it.
What I want is:
Always colored output
Scrolling by touchpad or mouse
Quit-if-one-screen
And my current configuration is:
$ git config --global core.pager
less -+F -+X -+S
This does everything except the last one.
But, if I remove -+F, there will be no output in case of one-screen. If I remove -+X as well, the output is back but I cannot scroll by touchpad in less.
Is there a workaround which can meet all the requirements above?
|
UPDATE
tl;dr Solution: upgrade to less 530
From http://www.greenwoodsoftware.com/less/news.530.html:
Don't output terminal init sequence if using -F and file fits on one screen.
So with this fix we don't even need to bother determining whether to use -X on our own, less -F just takes care of it.
PS. Some other less configs that I use:
export PAGER='less -F -S -R -M -i'
export MANPAGER='less -R -M -i +Gg'
git config --global core.pager 'less -F -S -R -i'
#alias less='less -F -S -R -M -i'
I eventually ended up with writing a wrapper on my own.
#!/usr/local/bin/bash
# BSD/OSX compatibility
[[ $(type -p gsed) ]] && SED=$(type -p gsed) || SED=$(type -p sed)
CONTEXT=$(expand <&0)
[[ ${#CONTEXT} -eq 0 ]] && exit 0
CONTEXT_NONCOLOR=$( $SED -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g" <<< "$CONTEXT")
LINE_COUNT=$( (fold -w $(tput cols) | wc -l) <<< "$CONTEXT_NONCOLOR" )
[[ $LINE_COUNT -ge $(tput lines) ]] && less -+X -+S -R <<< "$CONTEXT" || echo "$CONTEXT"
BSD/OSX users should manually install gnu-sed. The amazing regexp, which helps remove color codes, is from https://stackoverflow.com/a/18000433/2487227
I've saved this script to /usr/local/bin/pager and then git config --global core.pager /usr/local/bin/pager
The treatment for OCD patients, hooray!
| How to use "less -F" without "-X", but still display output if only one page? |
1,409,919,431,000 |
I am attempting to install git on Debian 8.6 Jessie and have run into some dependency issues. What's odd is that I didn't have any issues the few times I recently installed Git in a VM while I was getting used to Linux.
apt-get install git
Results in:
The following packages have unmet dependencies:
git : Depends: liberror-perl but is not installable
Recommends: rsync but it is not installable
E: Unable to correct problems, you have held broken packages.
UPDATE
my sources.list
Seems to be an issue with my system. I can no longer properly install anything. I'm getting dependency issues installing things like Pulseaudio which I've previously installed successfully a few days ago.
|
You should edit your sources.list , by adding the following line:
deb http://ftp.ca.debian.org/debian/ jessie main contrib
Then upgrade your package and install git:
apt-get update && apt-get upgrade && apt-get dist-upgrade
apt-get -f install
apt-get install git
Edit
the following package git , liberror-perl and [rsync]3 can be downloaded from the main repo , because you don't have the main repo on your sources.list you cannot install git and its dependencies .
Your sources.list should be (with non-free packages):
deb http://ftp.ca.debian.org/debian/ jessie main contrib non-free
deb-src http://ftp.ca.debian.org/debian/ jessie main contrib non-free
deb http://security.debian.org/ jessie/updates main contrib non-free
deb-src http://security.debian.org/ jessie/updates main contrib non-free
deb http://ftp.ca.debian.org/debian/ jessie-updates main contrib non-free
deb-src http://ftp.ca.debian.org/debian/ jessie-updates main contrib non-free
deb http://ftp.ca.debian.org/debian/ jessie-backports main contrib non-free
On debian Stretch your /etc/apt/sources.list should be (at least):
deb http://deb.debian.org/debian stretch main
deb http://security.debian.org/ stretch/updates main
deb http://deb.debian.org/debian/ stretch-updates main
| Unmet dependencies while installing Git on Debian |
1,409,919,431,000 |
I have googling awhile, but can not find such information. Looks like git doesn't contain users and groups, only permissions. Am I right?
|
See the Content Limitations section of the git Wiki: git does not track file ownership, group membership, doesn't track most permission bits, ACLs, access and modification times, etc.
Git tracks contents, and doesn't care much about pretty much everything else.
| Does git contain information about used id / group id changes? |
1,409,919,431,000 |
I want to build a debian package with git build package.(gbp)
I passed all steps, and at least, when I entered gbp buildpackage, This error appeared.
what does it mean?
and what should I do?
gbp:error: upstream/1.5.13 is not a valid treeish
|
The current tag/branch you are in, is not a Debian source tree, it doesn't contain the debian/ directory in its root. This is evident because you are using a "upstream/" branch, a name utilized to upload the pristine source tree to git repositories. Try using the branch stable, testing or unstable, or any branch that starts with Debian or a commit tagged using the Debian versioning scheme.
| what does " gbp:error: upstream/1.5.13 is not a valid treeish" mean? |
1,409,919,431,000 |
Is there any linux distro that has a git based package manager/installer. I want something similar to FreeBSD Ports (which is CVS based, I think) or Mac OS X Homebrew (git based).
|
There's Exherbo, which uses multiple Git repositories to store its exheres (its term for build recipes similar to Gentoo's ebuilds or BSD's ports). It's still a pretty young distribution, though.
Update: Gentoo recently moved to Git for its package repository. However, I don't think it's set up yet to have normal users get updates via Git (although I believe it's planned to allow that).
| Git based package manager/installer for Linux |
1,409,919,431,000 |
Heres the closest I've gotten: I installed gitolite in the /Private folder using ecryptfs-utils (sudo apt-get install ecryptfs-utils adduser git ecryptfs-setup-private then the rest was configuring gitolite using a root install).
It worked just fine as long as someone was logged in as the user git using a password (su git using root does not work). Since the private folder activates through logging in with a password and gitolite uses RSA keys (required) the private folder is hidden thus error occurs.
Is there a way I can log into my server after a reboot, type in the password and have the git user private folder available until next time the machine restarts?
Or maybe theres an easy way to encrypt a folder for git repositories?
|
You simply need to remove the file ~/.ecryptfs/auto-umount.
This file is a flag that pam_ecryptfs checks on logout. This file exists by default at setup, along with ~/.ecryptfs/auto-mount, such that your private directory is automatically mounted and unmounted at login/logout. But each can be removed independently to change that behavior. Enjoy!
| How do I encrypt git on my server? |
1,409,919,431,000 |
Every time I do git pull or git reset, git resets changes to permissions and ownership I made. See for yourself:
#!/usr/bin/env bash
rm -rf 1 2
mkdir 1
cd 1
git init
echo 1 > 1 && git add 1 && git ci -m 1
git clone . ../2
cd $_
chmod 0640 1
chgrp http 1
cd ../1
echo 12 > 1 && git ci -am 2
cd ../2
stat 1
git pull
stat 1
The output:
$ ./1.sh 2>/dev/null | grep -F 'Access: ('
Access: (0640/-rw-r-----) Uid: ( 1000/ yuri) Gid: ( 33/ http)
Access: (0664/-rw-rw-r--) Uid: ( 1000/ yuri) Gid: ( 1000/ yuri)
Is there a way to work around it?
I want to make some files/directories accessible for writing by the web server.
|
This sounds like the user you're running has the default group set to yuri. You can confirm this like so:
$ id -a
uid=1000(saml) gid=1000(saml) groups=1000(saml),10(wheel),989(wireshark)
The UID of your account is this: uid=1000(saml) whereas the default group is git=1000(saml) and any secondary groups are thereafter.
NOTE: If you want the git clone to have specific ownership, then you have at least 2 options.
Option #1
Set a parent directory with the permissions as you want like so:
$ mkdir topdir
$ chgrp http topdir
$ chmod g+s topdir
$ cd topdir
$ git clone ....
This forced the directory topdir to enforce any child directories underneath it to have the group http applied. This will work by in large but can lead to problems, since if you move files into this git clone workspace, those files will not have their groups enforced by the changes made above.
Option #2
Prior to doing work, change your default group to http like so:
$ newgrp http
$ git clone ...
This method will force any new files created to have their group set to http instead of your normal default group of yuri, but this will only work so long as you remember to do a newgrp prior to working in this workspace.
Other options
If neither of these seem acceptable you can try using ACLs instead on the git workspace directory. These are discussed in multiple Q&A's on this site, such as in this Q&A titled: Getting new files to inherit group permissions on Linux.
| Is there a way to prevent git from changing permissions and ownership on pull? |
1,409,919,431,000 |
My indention is to have a script that updates all git submodules according to which branch is given. If there's no such branch for a submodule, master is used.
This is what I have now:
#!/bin/bash -x
if [ -z $1 ]; then
echo "Branch name required."
exit
fi
function pbranch {
exists=`git show-ref refs/heads/$branch`
if [ -z $exists ]; then
branch="master"
fi
git co $branch
git pull origin $branch
}
branch=$1
git submodule foreach pbranch
But when running this script, the error is thrown:
oleq@pc ~/project> git-fetchmodules major
+ '[' -z major ']'
+ branch=major
+ git submodule foreach pbranch
Entering 'submodule'
/usr/lib/git-core/git-submodule: 1: eval: pbranch: not found
Stopping at 'submodule'; script returned non-zero status.
My guess is that git submodule foreach utilizes eval (according to the documentation), which I don't use correctly in this context.
There are billions of examples of how to use this command with "inline callback" but I couldn't found a single one with the callback in form of the function. Any idea how to solve this?
|
I resolved my issue by putting the function inside of the quotes as a callback:
#!/bin/bash
if [ -z $1 ]; then
echo "Branch name required."
exit
fi
git submodule foreach "
branch=$1;
exists=\$(git show-ref refs/heads/\$branch | cut -d ' ' -f1);
if [ -z \$exists ]; then
branch='master';
fi;
echo Checking branch \$branch for submodule \$name.;
git fetch --all -p;
git co \$branch;
git reset --hard origin/\$branch;
"
Note that variables like $1 are those from the script's namespace. The "escaped ones" like $\(bar), \$branch are evaluated within "the callback". It was pretty easy.
| Use git submodule foreach with function |
1,409,919,431,000 |
I have some problems with git-lfs and I think that upgrading to the latest git can fix this problems. Current version of git in Debian is 2.1.4, current stable version on official site is 2.6.4. Can I only build from source or maybe can I add some external repository?
|
As of December 2015, Debian stretch/sid has git version 2.6.4. If you don't want to upgrade your entire distribution, you can look into apt pinning to bring in only git and any necessary dependencies from stretch/sid. However, many Debian folks will tell you this sort of thing is a bad idea, so building from source or waiting/asking for a backport are the only officially recommended approaches.
| How to install latest git on Debian 8? |
1,409,919,431,000 |
$ git commit
error: cannot run vim: No such file or directory
error: There was a problem with the editor 'vim'.
Please supply the message using either -m or -F option.
How can I overcome the error and define the editor?
|
The answer was:
sudo apt-get install vim
as it was a new machine and vim wasn't installed.
| git commit error - cannot run vim: No such file or directory |
1,409,919,431,000 |
I have 3 users A,B and C inside a group 'admin'. I have another user 'D' in whose home directory, there is a project folder. I have made D as the owner of that folder and assigned 'admin' as the group using chgrp. Group and owners have all the permissions, but still A,B or C are unable to access the folder. I have two question :
Is it even possible for other users to access anything in another user's directory
Giving rights to a group only makes the users in that group have access to files that are outside any user's home directory ?
Edit : Here is how I had set the owner and group of the project
sudo chown -R D project
sudo chgrp -R admin project
I got an error while trying to get into the project folder within D's home directory (while being logged in as A)
cd /home/D/project
-bash: cd: /home/D/project: Permission denied
Here is the output of ls -la command :
drwxrwsr-x 7 D admin 4096 Nov 18 13:06 project
Here is the description of the group admin :
getent group admin
admin_users:x:501:A,B,C
Also note that group admin is not being listed when I type groups from the user D, but was visible when I used cut -d: -f1 /etc/group. The user I am referring to as D is actually ec2-user(the default Fedora user on Amazon servers)
Ultimately, I'm setting up a git repository on a server. I have created the repo in D's home directory, but wish A, B and C to have access to it too (and clone them)
|
Some points that seem to be necessary (though I freely admit that I am not expert in these matters), and that were not covered in RobertL's otherwise admirably thorough answer.
Make sure that the other users have actually logged into group admin:
A$ newgrp admin
Since the users are already in the group, I think you will not need to set a group password. If you do:
A$ sudo chgpasswd
admin:secret (typed into stdin)
Make sure that D's home directory is in group admin and is group-searchable.
D$ chgrp admin ~
D$ chmod g+x ~
D$ ls -lad ~
drwx--x--- 3 D admin 4096 Nov 24 19:25 /home/D
The directory needs to be searchable to allow users to enter it or its subdirectory project. It doesn't need to be group-readable, so D's own filenames are still private. To let the other users get to project easily, have them create symbolic links to it; otherwise, they'll have to type the whole path each time (autocomplete won't work because the shell can't read the pathname, it can only go to it).
| Can users in a group access a file that is in another user's home directory? |
1,409,919,431,000 |
Let's say I've got two repositories aye and bee and I want to get rid of bee, in such a way that the linear history of bee/master is "replayed" in a new subdirectory (several levels deep) of aye. I just want the files and the commit messages, I don't care about commit IDs. I do want a sensible history, so git subtree add --prefix=subdirectory and git read-tree --prefix=subdirectory/ are not what I'm looking for.
Both repositories are private, so there's no risk of rewriting history for someone else. However, bee does have a submodule cee.
|
First, rewrite bee's history to move all files into the subdirectory:
cd /path/to/bee
git filter-branch --force --prune-empty --tree-filter '
dir="my fancy/target directory"
if [ ! -e "$dir" ]
then
mkdir --parents "${dir}"
git ls-tree --name-only "$GIT_COMMIT" | xargs -I files mv files "$dir"
fi'
git log --stat should show every file appearing under my fancy/target directory. Now you can merge the history into aye with ease:
cd /path/to/aye
git remote add -f bee /path/to/bee
git checkout -b bee-master bee/master
git rebase master
git checkout master
git rebase bee-master
Recreate the submodule in aye:
git submodule add git://my-submodule 'my fancy/target directory/my-submodule'
Finally you can clean up aye:
git rm 'my fancy/target directory/.gitmodules'
git branch --delete --force bee-master
git remote remove bee
You may also have to fix any absolute paths in your repository (for example in .gitignore)
| How to replay Git repository history into subdirectory? |
1,409,919,431,000 |
The following works:
git -C ~/dotfiles status
But this fails:
git status -C ~/dotfiles
Why is this?
|
This is because -C is a global option, and doesn't "belong" to the status action. This is a common pattern, resulting in synopses like the one below:
command [global options] action [action-specific options]
git --help lists Git's global options, and man git goes into more detail.
| Why does position of -C matter in git commands? |
1,409,919,431,000 |
I want to create an inexpensive self-hosted private git server with redundant storage. To that end I have bought a Raspberry Pi and configured both git and ssh on the Pi. I can access the Pi both from a LAN and remotely (by forwarding a port on my router to the Pi).
So the git server is already up and running. The last thing to do is redundant storage. Because I have a 7-port USB hub attached to my Pi, I would like to set up a RAID system using multiple identical USB sticks.
I have only conceptual knowledge of RAID. Therefore I do not know how to set it up and more importantly, whether it is possible with USB sticks connected to a hub.
So these are basically my questions
Can you set up a RAID system using USB sticks as the storage media
What software should I use
Where can I find good tutorials / manuals for RAID systems
In case RAID is impossible, how can I synchronize data across multiple USB sticks
|
Q#1: Can you set up a RAID system using USB sticks as the storage media
You should be able to use any block storage devices in a RAID. Any standard directions for setting up a RAID using SATA HDD's should be applicable when using USB storage as well. You'll have to set it up so that the USB devices are assembled as members of the RAID array.
Q#2: What software should I use
I would use the mdadm software which is typically included with most Linux distros.
Example
$ sudo mdadm --create --verbose /dev/md0 --level=1 /dev/sda1 /dev/sdb1
mdadm: Note: this array has metadata at the start and
may not be suitable as a boot device. If you plan to
store '/boot' on this device please ensure that
your boot-loader understands md/v1.x metadata, or use
--metadata=0.90
mdadm: size set to 976629568K
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
Change the devices to the ones used by the USB storage devices. Then assemble the array:
$ sudo mdadm --assemble --scan
$ sudo mdadm --assemble /dev/md0 /dev/sda1 /dev/sdb1
Once assembled:
$ sudo mdadm --detail /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Fri Jul 5 15:43:54 2013
Raid Level : raid1
Array Size : 976629568 (931.39 GiB 1000.07 GB)
Used Dev Size : 976629568 (931.39 GiB 1000.07 GB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent
Update Time : Fri Jul 5 21:45:27 2013
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
Name : msit01.mysolutions.it:0 (local to host msit01.mysolutions.it)
UUID : cb692413:bc45bca8:4d49674b:31b88475
Events : 17
Number Major Minor RaidDevice State
0 8 1 0 active sync /dev/sda1
1 8 17 1 active sync /dev/sdb1
Now format the RAID array with a filesystem:
$ sudo mke2fs /dev/md0
mke2fs 1.42 (29-Nov-2011)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
61046784 inodes, 244157392 blocks
12207869 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
7452 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000, 214990848
Allocating group tables: done
Writing inode tables: done
Writing superblocks and filesystem accounting information: done
Q#3: Where can I find good tutorials / manuals for RAID systems
A simple search on Google will turn up many options. For example this one: Tutorial: mdadm Software RAID on Ubuntu / Debian Systems.
| How to setup a RAID system using USB sticks as storage media |
1,409,919,431,000 |
I am trying to make an alias for mv so it does its normal behaviour in normal folders and is replaced by git mv inside git repositories. I tried many ways. The if statement works, only the command git mv will not run correctly.
alias mv='"$(
if [ x`git rev-parse --show-toplevel 2> /dev/null` = x ];
echo mv;
else
echo "git mv";
fi)"'
|
I would use a function for that, like so:
gitmv()
{
# If in a git repo - call git mv. otherwise- call mv
if [ x`git rev-parse --show-toplevel 2> /dev/null` = x ];
then
mv "$@"
else
git mv "$@"
fi
}
Edit:
alias mv=gitmv
| if-then-else inside Bash Alias |
1,409,919,431,000 |
I just made a simple script and created a new repository for it on GitHub. After initializing the local repo, moving the script to the repository and pulling the GitHub repository (containing only a README.md file), the script was gone. Is this normal behavior? And is there some way to restore the file?
Here are the commands, as executed:
$ mkgithub ~/dev/cr2meta2jpg
Initialized empty Git repository in /home/username/dev/cr2meta2jpg/.git/
$ mv test.sh ~/dev/cr2meta2jpg/cr2meta2jpg.sh
$ cd ~/dev/cr2meta2jpg/
$ ls
cr2meta2jpg.sh
$ git pull
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From github.com:l0b0/cr2meta2jpg
* [new branch] master -> origin/master
$ ls
README.md
|
A git pull will not overwrite local changes unless you use git add before. Even in this case, you can still recover your data.
When you issued git add before the pull:
mkgithub blub
cp test.sh blub/
cd blub/
git add test.sh
git pull
The pull will delete test.sh. It will only do this if you have no commit in the local repo. After adding a commit this won't remove test.sh (git either ignores it or reports a merge conflict)
The file is not lost. It's still in the Git repository as a dangling blob.
To recover the file:
$ git fsck
Checking object directories: 100% (256/256), done.
Checking objects: 100% (401/401), done.
dangling blob 541060d8292ff808c9715265d063f1bae220da7c
$ git show 541060d8292ff808c9715265d063f1bae220da7 > test.sh
This works as long as you did not issue git gc --prune=now afterwards.
| Does git pull after init remove untracked files? |
1,409,919,431,000 |
I can do git clone like so ...
git clone https://github.com/stackforge/puppet-heat.git
... with no problems. But I want to exclude all the git meta stuff that comes with the cloning, so I figured I would use git archive but I get this error:
$ git archive --remote=https://github.com/stackforge/puppet-heat.git
fatal: Operation not supported by protocol.
Anyone know why or what I am doing wrong?
|
I would simply run the git clone as you've described and then delete the .git directories that are dispersed throughout the cloned directory.
$ find puppet-heat/ -name '.git' -exec rm -fr {} +
| git archive fatal: Operation not supported by protocol |
1,409,919,431,000 |
I have a custom Zsh function g:
function g() {
# Handle arguments [...]
}
Within it, I handle short arguments that execute Git commands. For example:
g ls # Executes git ls-files ...
g g # Executes git grep ...
I need to be able to set the autocompletion rules to Git's rules for the short arguments but I am unsure of how to do this.
For example, I need g ls <TAB> to tab-complete the rules for git ls-files <TAB> which would give me the arguments for git ls-files:
$ g ls --<TAB>
--abbrev -- set minimum SHA1 display-length
--cached -- show cached files in output
--deleted -- show deleted files in output
# Etc...
This is not simply setting g to autocomplete for git since I'm mapping my custom short commands to the Git commands.
|
I found /usr/share/zsh/functions/Completion/Unix/_git which had some tips for aliases like this and ended up defining these functions for the aliases:
_git-ls () {
# Just return the _git-ls-files autocomplete function
_git-ls-files
}
Then, I did a straight compdef g=git. The autocomplete system will see that you are running, for example, g ls and use the _git-ls autocomplete function.
Thanks to user67060 for steering me in the right direction.
| How do I set Zsh autocompletion rules for second argument (of function) to an existing command's rules? |
1,409,919,431,000 |
This is my Git repository:
https://github.com/benqzq/ulcwe
It has a dir named local and I want to change its name to another name (say, from local to xyz).
Changing it through GitHub GUI manually is a nightmare as I have to change the directory name for each file separately (GitHub has yet to include a "Directory rename" functionality, believe it or not).
After installing Git, I tried this command:
git remote https://github.com/benqzq/ulcwe && git mv local xyz && exit
While I didn't get any prompt for my GitHub password, I did get this error:
fatal: Not a git repository (or any parent up to mount point /mnt/c)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
I know the whole point in Git is to download a project, change, test, and then push to the hosting provider (GitHub in this case), but to just change a directory, I desire a direct operation. Is it even possible with Git?
Should I use another program maybe?
|
The fatal error message indicates you’re working from somewhere that’s not a clone of your git repository. So let’s start by cloning the git repository first:
git clone https://github.com/benqzq/ulcwe.git
Then enter it:
cd ulcwe
and rename the directory:
git mv local xyz
For the change to be shareable, you need to commit it:
git commit -m "Rename local to xyz"
Now you can push it to your remote git repository:
git push
and you’ll see the change in the GitHub interface.
| Change a directory name in a Github repository remotely, directly from local Linux Git? |
1,409,919,431,000 |
Is it possible to use a commit message from stdout, like:
echo "Test commit" | git commit -
Tried also to echo the message content in .git/COMMIT_EDITMSG, but then running git commit would ask to add changes in mentioned file.
|
You can use the -F <file>, --file=<file> option.
echo "Test commit" | git commit -F -
Its usage is described in the man page for git commit:
Take the commit message from the given file. Use - to read the message from
the standard input.
| Git commit using stdout from bash? |
1,409,919,431,000 |
This is, how I download various master branches from GitHub, and I aim to have a prettier script (and maybe more reliable?).
wget -P ~/ https://github.com/user/repository/archive/master.zip
unzip ~/master.zip
mv ~/*-master ~/dir-name
Can this be shorten to one line somehow, maybe with tar and pipe?
Please address issues of downloading directly to the home directory ~/ and having a certain name for the directory (mv really needed?).
|
The shortest way that seems to be what you want would be git clone https://github.com/user/repository --depth 1 --branch=master ~/dir-name. This will only copy the master branch, it will copy as little extra information as possible, and it will store it in ~/dir-name.
| Shortest way to download from GitHub |
1,409,919,431,000 |
I'm trying to get the most recent version of Git installed onto my Debian Buster machine, and I'm running into trouble. The most recent version of Git on stable is 2.20. I found that the testing branch has the right version, but I'm not having any success with backports. I've added
deb http://deb.debian.org/debian/ buster-backports main contrib
deb-src http://deb.debian.org/debian/ buster-backports main contrib
to /etc/apt/sources.list and done sudo apt-get update, but every time I run sudo apt-get -t buster-backports install git I end up with 2.20 again. I've also tried using apt-get to remove git and then install it, but no luck. Any advice?
Thanks!
|
Since February 2020, a new-enough version of git is available in Buster backports (2.30.2 since June 2021); to install that, run
sudo apt install -t buster-backports git
Readers who haven’t already enabled Buster backports will need to run
echo deb http://deb.debian.org/debian buster-backports main | sudo tee /etc/apt/sources.list.d/buster-backports.list
sudo apt update
first.
The rest of the answer is obsolete with respect to the actual question, but can be applied generally for other packages (at least, for the current release of Debian, which is no longer Buster).
To get version 2.24 or later, in the absence of a backport I recommended two approaches: ask for a backport, or build the 2.24 source package.
To ask for a backport, file a wishlist bug on git using reportbug. Backports have been made available in the past, so there’s a decent chance someone will provide one if you explain why you want it.
To build a newer package from source, run
sudo apt-get install devscripts dpkg-dev build-essential
sudo apt-get build-dep git
dget https://deb.debian.org/debian/pool/main/g/git/git_2.24.1-1.dsc
cd git-2.24.1
dpkg-buildpackage -us -uc
You can replace git_2.24.1-1.dsc and git-2.24.1 with whatever is appropriate for the version you wish to install; see the Debian package tracker to find out which versions are available as source packages.
This will install the necessary build dependencies and build the packages. You can then install the ones you need using sudo dpkg -i.
It’s not worth upgrading all your distribution to testing, just to get a newer version of git...
| How do I get Git 2.24 installed on Debian Buster? |
1,409,919,431,000 |
When I view a large diff with git diff, it gets paged with less. This is confirmed by opening another window and checking data from ps -aux and /proc.
However, when less is invoked by Git, it does not revert the terminal content to its previous state after hitting q (the diff content remains in terminal). But when I do
git diff commit1 commit2 --color | less -R
and quit less with a key q, the content disappears and the terminal reverts to the previous state.
More interestingly, if I do these
export PAGER=less LESS='-R'
and invoke git diff (or any other command that calls a pager), less behaves the same as if invoked directly from Bash shell.
Here's a brief screenshot describing my question. On the left pane the command are executed as following:
unset PAGER GIT_PAGER LESS
git diff HEAD^ HEAD
On the right pane you see the commands. The latest commit was 100+ lines of y written to a file. On both panes less is exited with key q.
Can anyone tell me what is different and explain why?
|
Documentation:
When the LESS environment variable is unset, Git sets it to FRX (if LESS environment variable is set, Git does not change it at all).
The -X (--no-init) option is responsible for not clearing terminal after exit of less.
| `less` performs differently when invoked from Bash and from Git |
1,409,919,431,000 |
I have the following entries in a .gitignore file and I want to remove them. The reason why is because these files are temporary-junk files created during a TeX compilation and I want to be able to remove them.
How I can do that?
|
In your case if the files entries in your .gitignore are not starting with ! then this one-liner should be fine to you:
while read -r entry;do rm -rf ${entry}; done < .gitignore
| Delete any file mentioned in .gitignore |
1,409,919,431,000 |
Is there a way to tell git to only use so much bandwidth while cloning a repo?
I may have multiple applications - each of which demands different network speeds. Is there a way to tell git to do this? I only want to do it for this session, not every time.
|
Yes, there's always trickle. Install it, then try something like trickle -sd 50 git clone.
-s is for standalone mode, -d is for download limit, in KB/s
| Is there a way to throttle git while it's cloning a repo? |
1,409,919,431,000 |
I'm using bash version 4.1.2(1)-release (x86_64-redhat-linux-gnu) on cygwin with git 1.7.1. I wanted to make an alias for a command that needed to use the input argument twice. Following these instructions, I wrote
[alias]
branch-excise = !sh -c 'git branch -D $1; git push origin --delete $1' --
and I get this error:
$> git branch-excise my-branch
sh: -c: line 0: unexpected EOF while looking for matching `''
sh: -c: line 1: syntax error: unexpected end of file
I've tried both a - and a -- at the end, but I get the same errors. How can I fix this?
|
man git-config says:
The syntax is fairly flexible and permissive; whitespaces are mostly
ignored. The # and ; characters begin comments to the end of line,
blank lines are ignored.
So:
branch-excise = !bash -c 'git branch -D $1; git push origin --delete $1'
is an equivalent to:
#!/usr/bin/env bash
bash -c 'git branch -D $1
Running the above script prints:
/tmp/quote.sh: line 3: unexpected EOF while looking for matching `''
/tmp/quote.sh: line 4: syntax error: unexpected end of file
One solution is to put a whole command in ":
branch-excise = !"bash -c 'git branch -D $1; git push origin --delete $1'"
However, it still doesn't work because $1 is empty:
$ git branch-excise master
fatal: branch name required
fatal: --delete doesn't make sense without any refs
In order to make it work you need to create a dummy function in .gitconfig and call it like this:
branch-excise = ! "ddd () { git branch -D $1; git push origin --delete $1; }; ddd"
Usage:
$ git branch-excise master
error: Cannot delete the branch 'master' which you are currently on.
(...)
| Errors with git alias shell command |
1,409,919,431,000 |
I have a folder with several repositories inside. Is there any way I can run git branch or whatever git command inside each folder?
$ ls
project1 project2 project3 project4
And I'd like to have some kind of output like the following
$ command
project1 [master]
project2 [dev]
project3 [master]
project4 [master]
|
Try this. $1 should be the parent dir containing all of your repositories (or use "." for the current dir):
#!/bin/bash
function git_branches()
{
if [[ -z "$1" ]]; then
echo "Usage: $FUNCNAME <dir>" >&2
return 1
fi
if [[ ! -d "$1" ]]; then
echo "Invalid dir specified: '${1}'"
return 1
fi
# Subshell so we don't end up in a different dir than where we started.
(
cd "$1"
for sub in *; do
[[ -d "${sub}/.git" ]] || continue
echo "$sub [$(cd "$sub"; git branch | grep '^\*' | cut -d' ' -f2)]"
done
)
}
You can make this its own script (but replace $FUNCNAME with $0), or keep it inside a function and use it in your scripts.
| Get git branch from several folders/repos |
1,409,919,431,000 |
I'm recently trying to start my own project on a community git repo, and I've been having some complications. I'm new to git, but here's what I've been trying to do to just test it.
I run the following commands and they all run ok.
git config --global user.name "MYNAME"
git config --global user.email "MYEMAIL"
mkdir testproject
cd testproject
git init
touch README
git add README
git commit -m 'first commit'
git remote add origin [email protected]:community/testproject.git
and all of the above commands run with no error. However, when I the run the next command I get a huge error.
git push -u origin master
and the error is.
Counting objects: 3, done.
Writing objects: 100% (3/3), 204 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
Username for 'http://git.xxxxxx.org': MYEMAIL
Password for 'http://[email protected]':
remote: /usr/local/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/spec_set.rb:92:in `block in materialize': Could not find rake-10.1.0 in any of the sources (Bundler::GemNotFound)
remote: from /usr/local/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/spec_set.rb:85:in `map!'
remote: from /usr/local/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/spec_set.rb:85:in `materialize'
remote: from /usr/local/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/definition.rb:114:in `specs'
remote: from /usr/local/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/definition.rb:159:in `specs_for'
remote: from /usr/local/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/definition.rb:148:in `requested_specs'
remote: from /usr/local/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/environment.rb:18:in `requested_specs'
remote: from /usr/local/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/runtime.rb:13:in `setup'
remote: from /usr/local/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler.rb:120:in `setup'
remote: from /usr/local/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/setup.rb:17:in `<top (required)>'
remote: from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
remote: from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
remote: error: hook declined to update refs/heads/master
To http://git.xxxxxx.org/community/testproject.git
! [remote rejected] master -> master (hook declined)
error: failed to push some refs to 'http://git.xxxxxx.org/community/testprojact.git'
I'm not really sure what to do from here, but any help is much appreciated.
Also, I'm running Arch if it matters.
Edit:
I've tried re-installing rake and it didn't work. My current version of rake was 10.1.1, so I tried removing it and replacing it with version 10.1.0 and that also didn't fix it.
However when I was installing rake, I got an error:
WARNING: You don't have /home/josh/.gem/ruby/2.0.0/bin in your PATH,
gem executables will not run.
Could this be contributing to the problem?
|
That the remote declined to receive the data is only a side effect of the real problem -- git thinks that it was denied because one of the hooks on the remote end failed with an exit status >0 (you can see what it was in the Ruby traceback). It seems that one of the hooks tries to use rake, and can't find it. This is not a problem with your specific repo, probably. That message is also not from your local computer -- notice that it is prefixed with "remote", it is the remote that is missing rake, so probably only a sysadmin on that side can fix the issue.
I would suggest you contact whoever manages your community git repository.
| git push fails with remote: error: hook declined to update refs/heads/master |
1,409,919,431,000 |
I'm looking for a tool, or for suggestions towards a script, that would be able to search a Git repository for files based on both filenames and file contents (find/grep-like). It would need to be able to search not just in the currently checked out branch, but through that branch's history as well as in other branches.
The very specific example of a Git repository that I have is a checkout of dspinellis' unix-history-repo. I often look for historical implementations of things in there, but it's a pain to track down files as I often need to guess what branch I need to be looking at (there are 165 branches in that repository).
Example of thing I would like to do with this tool is to find the wow command, which may have been an external command or a built-in command in sh or csh at some point, if it existed as part of some early BSD Unix (if it existed at all). To do this, I would want to search for wow.* as a filename pattern, and also for files that may at some point have included a wow C function, across the 165 branches of dspinellis' Git repository.
|
Heh, guess what I’ve been doing too...
To look for a file name across all branches, I use
git log --all --name-only --pretty=format:%H -- wow\*
wow can be replaced by any glob. This runs quite quickly on the Unix history repository. The format shows the hash leading to the creation of the matching file, so you can then check the tree out at that point and explore further.
To search file contents across all branches, I use
git rev-list --all | xargs git grep "excited too"
which lists all commit objects and searches through them. This is very, very slow on the Unix history repository; listing all the branches and grepping there is quicker:
git grep "excited too" $(git branch -r | awk '{print $1}')
| Tool for searching across branches and through history in a Git repository |
1,610,403,173,000 |
I have a problem with the certificates in Arch linux. It seems that it can't find ca-certificates.crt. I have updated my system and installed the ca-certificates{,-utils,-mozilla} packages and it still doesn't work.
git clone http://github.com/sstephenson/bats.git
Cloning into 'bats'...
fatal: unable to access 'https://github.com/sstephenson/bats.git/': error setting certificate verify locations:
CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: none
|
I am posting an answer to my own question because I solved the problem and I did not find a valid solution elsewhere. There is no /etc/ssl/certs/ca-certificate-crt file. So a link needs to be provided to the proper cert.
$ ln -s /etc/ca-certificates/extracted/ca-bundle.trust.crt /etc/ssl/certs/ca-certificates.crt
Now I can curl and git clone through https.
| Arch linux ca-certificates.crt not found |
1,610,403,173,000 |
-n works as a grep argument to display the line number, but -H doesn't for filename. I think it is because git diff doesn't by default output filename for each changed line. As I was typing, I considered another option to display multiple lines and it solved my immediate problem, but would still like to know the solution to display the actual filename.
[michael@bigbox www]$ git diff | grep -n -H "this->config"
(standard input):614:- $config=json_decode($this->config,true);
[michael@bigbox www]$
|
I’m not sure you can show both the filename and the changed line in a single command, but the following will list all files where a line containing this->config has changed:
git diff --name-only -G"this->config"
| Display filename of git diff filtered by term |
1,610,403,173,000 |
so git archive --format=tar HEAD will give me a tar archive of the latest commit on the current branch. Is there a version that would include local modifications to tracked files that have not yet been committed?
|
The git way is to commit everything. Remember, branches are cheap.
git checkout -b intermediate-releases/20140414
git commit -m 'Wibble wobble wubble'
Then restore your working copy — I don't know to do that reliably but I'm sure there's a way. Now you can make an archive of the new branch's tip:
git archive intermediate-releases/20140414 | gzip >20140414.tgz
If you really don't want to keep track of that archive (but why not?), you could make a stash, which has the advantage of making it really easy to restore the working copy.
git stash
git archive 'stash@{0}' | gzip >whatever.tgz
git stash pop
If you absolutely don't want to make any change to the working copy, you can use git ls-files to retrieve the list of files and archive these.
git ls-files HEAD | tar -czf whaterver.tgz -T -
| git archive including uncommitted modified files |
1,610,403,173,000 |
How do I select all the files ending with .txt in the current directory, but omit all the ones in the subdirectories?
*.txt selects all the files ending in .txt in the subdirectories as well. How do I omit them?
directory structure:
current folder
|-first_file.txt
|-sub_folder
|-second_file
I'm trying to add the first_file alone to a git repository. But doing git add *.txt adds both the first and the second file to the stage. I want only the first_file to be added.
|
There is a subtle difference between whether the shell or git handle the pattern. git considers subdirectories as well, the shell doesn't. So in your case, running
git add *.txt
while the current directory is your "current folder" lets the shell do the wildcard expansion (and therefore only adds matching files in the current directory).
To elaborate
With git add *.txt wildcard expansion is done by the shell, so git actually gets called with git add file1.txt file2.txt (which means that git just takes the file names passed and adds them). Only caveat here is that if there are no files matching *.txt git gets run as git add *.txt nevertheless which of course will trigger gits subdirectory scan
With git add '*.txt' wildcard expansion is done by git which always implies a subdirectory scan as well.
| How can I get git to select txt files in the current directory alone |
1,610,403,173,000 |
I find both of these can unstage a file.
I used to use git reset file to unstage a file.
But today when I read the http://git-scm.com/book.
I find it taught me to use git reset HEAD file, what does the HEAD do here? In which circumstances it's a must?
PS: An additional question, I can use git checkout file to unmodified a file. Meanwhile this book suggest me to use git checkout -- file. What's the difference here?
|
There's no difference. HEAD is entirely optional. HEAD normally points to the last commit of the current branch. If you don't use it, it's implied. It makes sense only if you want to reset file based on some different branch or commit etc. In other words, it makes sense to use something else than HEAD.
git checkout with -- is safer. It's clear that whatever follows -- is a path and not a commit or a tag for example.
| What's the difference between `git reset file` and `git reset HEAD file`? |
1,610,403,173,000 |
I have a corporate Linux server which does not have internet connection, and sudo access needs to be approved through many levels of hierachy. I've tried install git but I soon realized this needs a whole bunch of dependencies like C compiler to install, of which I do not have the dependencies.
What I need is a method to have git on my server, maybe installing it as a standalone, taking care of the dependencies that are required, without internet or preferbly sudo. It's very straight forward in windows box, but I am stuck for Linux.
Problem with this solution is that it still requires sudo.
Help please!
|
I found a solution that works. To iterate my steps:
1) Download relevant RPM (or here)
2) Copy to Linux server and upack using (replace filename as
necessary)
rpm2cpio git-1.7.9.6-1.el6.rfx.x86_64.rpm | cpio -idmv
3) Update $PATH:
PATH=$PATH:<your path to git>/usr/bin
4) Now see it work
git --version
| Install Git offline without sudo |
1,610,403,173,000 |
I'm used to create some manually-made repositories to push code to my pet server or share code inside my company. I use the URL ssh://user@ip/folder.git to add as remotes to my workspaces.
I was wondering how services like GitHub set repository URLs without the protocol spec, like [email protected]:igorsantos07/Restler.git.
|
If you take a look at the Git book accessible here: 4.1 Git on the Server - The Protocols there is mention of the various formats for the protocols that Git will accept.
excerpt
Probably the most common transport protocol for Git is SSH. This is because SSH access to servers is already set up in most places — and if it isn’t, it’s easy to do. SSH is also the only network-based protocol that you can easily read from and write to. The other two network protocols (HTTP and Git) are generally read-only, so even if you have them available for the unwashed masses, you still need SSH for your own write commands. SSH is also an authenticated network protocol; and because it’s ubiquitous, it’s generally easy to set up and use.
To clone a Git repository over SSH, you can specify ssh:// URL like this:
$ git clone ssh://user@server/project.git
Or you can use the shorter scp-like syntax for SSH protocol:
$ git clone user@server:project.git
You can also not specify a user, and Git assumes the user you’re currently logged in as.
Services such as GitHub play other tricks with the access to repositories by essentially wrapping the access using HTTP and then emitting the correct protocols out the backside of the HTTP server. This is typically done as a reverse proxy of sorts. A product that you can use that gives you some of these capabilities is called Gitolite (TOC or Intro) as well as Gitorious.
| Is it possible to remove "ssh://" from git remote's URLs? |
1,610,403,173,000 |
In my zsh shell, I am dynamically changing prompt depending on whether I am inside git repository or not. I am using following git command to check:
if $(git rev-parse --is-inside-work-tree >/dev/null 2>&1); then
...
now I also want to distinguish whether current directory is being ignored by git. So I have added one more check to my if statement:
if $(git rev-parse --is-inside-work-tree >/dev/null 2>&1) && ! $(git check-ignore . >/dev/null 2>&1); then
...
This works fine, but I was wondering whether I could simplify this into one git command. Since the prompt is refreshed on every ENTER, it tends to slow down the shell noticeably on some slower machines.
UPDATE
The accepted solution from @Stephen Kitt works great, except in following situation:
I am using repository across filesystems. Lets say git resides at /.git (because I want to track my config files in /etc), but I also want to track some files in /var/foo, which is a different partition/filesystem.
When I am located at / and execute following command, everything works as expected, and I get return code 1 (because /var/foo is being tracked):
# git check-ignore -q /var/foo
But when I am located anywhere in /var, the same command fails with error code 128 and following error message:
# git check-ignore -q /var/foo
fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
But I think this is only problem with the check-ignore command. Otherwise git seems to work fine across filesystem. I can track files in /var/foo fine.
The expected behavior should be that git check-ignore -q /var/foo returns 1, and git check-ignore -q /var/bar returns 0, if it is not being tracked.
how can I fix this problem?
|
git check-ignore . will fail with exit code 128 if . isn’t in a git repository (or any other error occurs), and with exit code 1 only if the path isn’t ignored. So you can check for the latter only:
git check-ignore -q . 2>/dev/null; if [ "$?" -ne "1" ]; then ...
Inside the then, you’re handling the case where . is ignored or not in a git repository.
To make this work across file system boundaries, set GIT_DISCOVERY_ACROSS_FILESYSTEM to true:
GIT_DISCOVERY_ACROSS_FILESYSTEM=true git check-ignore -q . 2>/dev/null; if [ "$?" -ne "1" ]; then ...
| zsh prompt: check whether inside git repository and not being ignored by git |
1,610,403,173,000 |
${$(git rev-parse HEAD):0:5}
bash: ${$(git rev-parse HEAD):0:5}: bad substitution
git rev-parse HEAD returns the hash id, but how do I make a substring out of it?
if I divide it into two lines, it works.
x=$(git rev-parse HEAD)
echo ${x:0:5}
But How do I do it in one line?
|
Using --short option:
$ git rev-parse --short=5 HEAD
90752
$ x=$(git rev-parse --short=5 HEAD)
$ printf '%s\n' "$x"
90752
| How to get first 5 chars of a git commit hash id and store it in a variable in bash? |
1,610,403,173,000 |
Whenever I try to create a signed git commit, I need to enter my GPG key. It spawns some GUI application to receive the password. It looked like the application was seahorse, so I uninstalled it, but git still uses some GUI app. Polybar doesn't report the application name and it's title is just [process]@MYPC.
How do I get git to use the command line / pinentry?
Versions:
gnuPG: 2.2.19
git: 2.25.1
pinentry: 1.1.0
|
What's in your ~/.gnupg/gpg-agent.conf?
I have pinentry-program /usr/bin/pinentry-curses in mine, and everything which uses gpg will ask for my pass-phrase in the terminal.
NOTE: You will need to restart your gpg-agent (or send it a HUP signal) if you change its config. Just running gpgconf --kill gpg-agent will do, gpg will restart it when needed.
ALSO NOTE: the environment variable GPG_TTY needs to be your current tty (i.e. the tty you're currently running gpg in - or whatever calls gpg, such as mutt, pass, git, etc). So add the following to your ~/.bashrc (or whatever's appropriate for your shell):
GPG_TTY=$(tty)
export GPG_TTY
See man gpg-agent for details.
| How do I get git to use the cli rather than some GUI application when asking for GPG password? |
1,610,403,173,000 |
I have a Makefile for a Latex project I'm working on. Makefiles aren't my forte, but is there a way to do something like:
make git "My comment"
And have the makefile execute:
git commit -m "My comment"
git push origin master
?
|
You could use a variable and read it from within the Makefile. Example:
git:
git commit -m "$m"
Then you can commit with: make git m="My comment".
| Git commit from within a Makefile |
1,610,403,173,000 |
I am using Git as many of you do. Also, I don't use any GUI for that — just CLI. So I was wondering: are there any way to make Git commands (git status, git checkout etc.) complete themselves when hitting Tab? Like other CLI commands do.
P.S. I'm using Arch Linux, if that anyhow matters.
|
Add source /usr/share/git/completion/git-completion.bash to your ~/.bashrc.
References
Arch Linux Wiki
| Git auto-complete |
1,610,403,173,000 |
I would like to use git to track changes in crontab.
I have initialized a new git repository in /var/spool/cron/crontabs/
Now the problem is, when crontab is saved, the second line of the header changes because it contains timestamp.
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.ubNueW/crontab installed on Thu Aug 1 06:29:24 2019)
What would be the easiest way to ignore these irrelevant changes ?
The possible duplicate question does not address the main point of my question: How to ignore the first 2 irrelevant lines from crontab. Instead, it addresses some other questions which I have not asked, such as some hooks.
|
You could use a filter:
git config filter.dropSecondLine.clean "sed '2d'"
Edit/create .git/info/attributes and add:
* filter=dropSecondLine
If you don't want the filter acting on all the files in the repo, modify the * to match an appropriate pattern or filename.
The effect will be the working directory will remain the same, but the repo blobs will not have the second line in the files. So if you pull it down elsewhere the second line would not appear (the result of the sed 'd2'). And if you change the second line of your log file you will be able to add it, but not commit it, as the change to the blob happens on add, at which point it will be the same file as the one in the repo.
| tracking crontab changes with git |
1,610,403,173,000 |
The example below is simplified to show the core of the problem, not the problem itself(my file tree is more complicated than that).
Let's say that I have two files I want to back up; one in ~/somedir/otherdir, the other in ~/otherdir/somedir/. I want to backup files from both directories in one git repository. How can I do this? Soft links only carry information about where file is stored, not the actual file, whereas hard links are somewhat foreign to me. Is this a case where hard links should be used?
Clarification: I want to use git because of four reasons: I want to store dotfiles/scripts/configurations that are text files and keep track of changes over time, I know git, I have a private git repository I could use to store them, and I want to be able to share these files across multiple PCs.
|
If you don't mind moving the files...
You could do this by moving the files into a git repository, and symlinking them to their old locations; you'd end up with
~/gitrepo/somedir/otherdir/file1 moved from ~/somedir/otherdir/file1
~/gitrepo/otherdir/somedir/file2 moved from ~/otherdir/somedir/file2
a symlink from ~/somedir/otherdir/file1 to ~/gitrepo/somedir/otherdir/file1
a symlink from ~/otherdir/somedir/file2 to ~/gitrepo/otherdir/somedir/file2
You can then safely commit the files in the git repository, and manipulate them using git, and anything using the old file paths will see whatever is current in the git workspace. Linking the files the other way round, or using hard links, would be dangerous because any git operation which re-writes the file (changing branches, reverting to a previous version...) would break the link. (Hopefully this explains why hard links aren't really a viable solution.)
With this kind of scenario you'll have to be careful with programs which re-write files completely, breaking links; many text editors do this, as do tools such as sed -i etc. A safer approach would be to move the entire folders into the git repository, and symlink the directories.
If you want to keep the files in place...
Another possibility is to create a git repository in your home directory, tell git to ignore everything, and then forcefully add the files you do want to track:
cd
git init
echo '*' > .gitignore
git add -f .gitignore
git commit -m "Initialise repository and ignore everything"
git add -f somedir/otherdir/file1
git commit -m "Add file1"
git add -f otherdir/somedir/file2
git commit -m "Add file2"
Once you've done this, you'll easily be able to track changes to files you've explicitly added, but git won't consider new files. With this setup it should also be safe to have other git repositories in subdirectories of your home directory, but I haven't checked in detail...
| How to backup files in multiple directories with git? |
1,610,403,173,000 |
I host my own git repository on a VPS. Let's say my user is john.
I'm using the ssh protocol to access my git repository, so my url is something like ssh://[email protected]/path/to/git/myrepo/.
Root is the owner of everything that's under /path/to/git
I'm attempting to give read/write access to john to everything which is under /path/to/git/myrepo
I've tried both chmod and setfacl to control access, but both fail the same way: they apply rights recursively (with the right options) to all the current existing subdirectories of /path/to/git/myrepo, but as soon as a new directory is created, my user can not write in the new directory.
I know that there are hooks in git that would allow me to reapply the rights after each commit, but I'm starting to think that I'm going the wrong way because this seems too complicated for a very basic purpose.
Q: How should I set up my right to give rw access to john to anything under /path/to/git/myrepo and make it resilient to tree structure change?
Q2: If I should take a step back change the general approach, please tell me.
Edit: The question was answered as is, but that was the wrong question. The right question would have been "How to configure a bare git repository on the server for use with ssh access?". See my own answer.
|
create a group myrepousers for example, and add your git users to that group.
Then change the group of everything under /path/to/git/myrepo to myrepousers:
chown -R .myrepousers /path/to/git/myrepo
Then fix the permissions:
chmod -R g+w /path/to/git/myrepo
find /path/to/git/myrepo -type d -exec chmod g+s {} \;
Should be all set.
| How to grant read/write to specific user in any existent or future subdirectory of a given directory? |
1,610,403,173,000 |
I need to copy a SINGLE FILE from LOCAL REPOSITORY to my machine, not git-pull or git-fetch, how can i do it?
Is it possible to get it via hash ?
such as a3ea2118bf1c5e2c6aa0974d0b6ff7415bd044ef ?
|
You can use git archive to obtain a single file from a repository:
git archive --remote=file:///path/to/repository.git HEAD:path/to/directory filename | tar -x
The repository specified as --remote can be local, remote, bare or regular, it works in all of the aforementioned cases.
Note that if you want to obtain a version of filename from a specific commit, you can replace HEAD in the oneliner above with the hash of the desired commit.
| copy a single file from local Git repository |
1,610,403,173,000 |
I want to download the patch series RFC PATCH 00/26 i.MX5/6 IPUv3 CSI/IC
In patchwork I can get access to individual patches https://patchwork.linuxtv.org/patch/24331/. But downloading 26 patches and then applying them one by one gets tedious. Is there a way to download the complete patch series with patchwork or by other means?
The question How do I get a linux kernel patch set from the mailing list? suggests marc.info and lkml.org for downloading individual patches but I want the whole series at once. How do I do that?
|
The patchwork project information page at https://patchwork.linuxtv.org/project/linux-media/ has a couple of links at the bottom to pwclient and a sample .pwclientrc
Once you set these up, you can use pwclient list to search for patches and pwclient git-am to apply them. The awkward part is that there's apparently no single command to search and apply in one go. I used a combination of the two to get (for example) Philipp Zabel's recent IPU CSI patch series like this...
pwclient list -w "Philipp Zabel" -s New v2 -f %{id} | egrep '^[0-9]' | xargs pwclient git-am
| How download complete patch series from patchwork? |
1,610,403,173,000 |
My configuration:
laptop: XPS 15 7590
system: Ubuntu 18.04
internet connection: wifi (5 GHz)
Every time I run git pull, git push I have to wait like 15 minutes until it is done. Same problem with running add-apt-repository ppa. As I was trying to solve it, I found this question where the solution was running:
sudo sysctl net.ipv6.conf.all.disable_ipv6=1
which is disabling IPv6 until next reboot. It really works. I would like to understand why exactly is this helping and also what can/should be done (set up) to make this permanent. And is it actually okay to set this permanently?
|
In order to make this permanent, open your /etc/sysctl.conf file using sudo
sudo nano /etc/sysctl.conf
Add the line at the bottom of the file:
net.ipv6.conf.all.disable_ipv6=1
After that you may reboot your machine or run
sudo sysctl -p
Alternatively, you may instruct your ssh client to use ipv4 only. To do so, open ~/.ssh/config using vi or nano and add the following:
Host *
AddressFamily inet
AddressFamily in the ssh config instructs which type of address to use when connecting via ssh. Valid choices are any, inet, inet6. Selecting to use inet makes sure ssh does not use ipv6 at all.
Git (commands) use either ssh or http protocol when communicating over a network. Since you are most likely using ssh protocol for your git commands, and making ssh protocol only use ipv4, it resolves the slow connectivity issue related to ipv6.
Unfortunately, this alternative approach won't fix your add-apt-repository ppa
| Git push/pull taking too long - IPv6 issue |
1,610,403,173,000 |
I have a script with this snippet:
ssh-agent bash -c "ssh-add $SOME_KEY; \
git submodule update --init foo"
The script hangs while asking the user:
RSA key fingerprint is SHA256:[the fingerprint]
Are you sure you want to continue connecting (yes/no)?
How can I make the script continue (with a yes)?
I know that I can invoke ssh -o StrictHostKeyChecking=no to disable this but I'm calling git not ssh.
I know that I can configure ~/.ssh/config to disable strict key checking for that host--but I don't want to modify the user's system.
I know that I can chmod 000 ~/.ssh/known_hosts to disable key checking for that user, but I don't want to modify the user's system
I thought I could insert yes | in front of git but it doesn't seem to work.
|
From Stack Overflow, via muru, passing ssh options to git clone:
The recently released git 2.3 supports a new variable
"GIT_SSH_COMMAND" which can be used to define a command WITH
parameters.
GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" git clone user@host
$GIT_SSH_COMMAND takes precedence over $GIT_SSH, and is
interpreted by the shell, which allows additional arguments to be
included.
| How can I suppress host key checking with ssh-agent |
1,610,403,173,000 |
From the git-revert(1) manpage it is not clear to me what the exact differences between the quit and abort options of the revert command are.
From my exercises with the revert command I made the observation that the abort option works very similar to the one of the rebase command in that it tries to reconstruct the pre-operational state of the current branch.
Also what are the practical use cases of the quit option?
|
From my exercises with the revert command I made the observation that the abort option works very similar to the one of the rebase command in that it tries to reconstruct the pre-operational state of the current branch.
You're on the right track:
git revert --abort rolls the sequencer state back, so the workspace and history end up as they were before the start of git revert;
git revert --quit only removes the sequencer state, so the workspace and history remain as they are (with a partial revert in progress but forgotten about).
From my quick experimentation, if a revert needs manual intervention, git revert --quit only forgets the previous commits; REVERT_HEAD remains in place so you still need to --continue or --abort. The latter keeps the forgotten commits as a result of the --quit.
As far as use cases go, I've never needed to use --quit, but I'd imagine if you're part-way through a revert and decide you're not going to need the remaining reverts, but you do want to keep those you've committed so far, then it might come in handy...
| What is git revert --quit for? |
1,610,403,173,000 |
I manually installed git 1.6 a year or two ago.
I noticed today that the 1.7 version is available in yum, and installed it (package git-all)
I now get the following output:
[root@ovz5197 ~]# git --version
bash: /usr/local/bin/git: No such file or directory
[root@ovz5197 ~]# which git
/usr/bin/git
[root@ovz5197 ~]# /usr/bin/git --version
git version 1.7.4.1
[root@ovz5197 ~]#
Any idea why the output of which seems to contradict the first line above?
|
If you had already run git from this instance of bash back when there was a /usr/local/bin/git, it's remembering the old location in a cache. Run hash -r to clear the cache. Each instance of bash has its own cache, so newly started instances of bash will look in the right place.
Otherwise, you evidently have a file /usr/local/bin/git, and it's executable, but it doesn't work because its loader is not present on the system. See Getting "Not found" message when running a 32-bit binary on a 64-bit system for a similar case.
| Multiple installed versions of git - centos |
1,610,403,173,000 |
Is there a way to make git handle a symlink as if it was a file. If I just normally add a symlink like git add symlink, git just stores/controlls the path to the file, not the linked file.
Is it possible to make git handle a symlink as if it was the linked file itself?
|
Sounds like you want a hard link
ln sourcefile /some/git/repo/targetfile
Only any good if the source and target locations are within the same file system. Otherwise you’ll have to settle for a copy or a symlink.
A symlink is a reference to a file.
A hard link is another name for an existing inode.
There are numerous resources on the web that explain in more detail.
I’m not using a special syntax to do with hard links. The man page for ln is a good place to look for the variations on syntax available.
| Git - handle symlink as if it was a file |
1,610,403,173,000 |
In zsh I am using the following function to delete a local and a remote branch with one command:
gpDo () {
git branch -d "$1" && git push --delete origin "$1"
}
Currently, auto-completion for the Git branch does not work. I have to manually type the whole branch name. How can I get tab completion working for such as function?
|
I assume you're using the “new” completion system enabled by compinit. If you're using oh-my-zsh, you are.
You need to tell zsh to use git branch names for gpDo. Git already comes with a way to complete branch names. As of zsh 5.0.7 this is the function __git_branch_names but this isn't a stable interface so it could change in other versions. To use this function, put this line in your .zshrc:
compdef __git_branch_names gpDo
With this declaration, completion after gpDo will only work after you've completed something on a git command line at least once. This is due to a quirk of function autoloading in zsh. Alternatively, run _git 2>/dev/null in your .zshrc; this causes an error because the completion function is called in an invalid context, but the error is harmless, and the side effect of loading _git and associated functions including __git_branch_names` remains.
Alternatively, define your own function for git branch completion. Quick-and-dirty way:
_JJD_git_branch_names () {
compadd "${(@)${(f)$(git branch -a)}#??}"
}
| zsh: Tab completion for function with Git commands |
1,610,403,173,000 |
After I clone a git repository locally, I want to switch branch to, says, 'ABCD'.
$ git branch -a
* master
remotes/origin/ABCD
remotes/origin/HEAD -> origin/master
remotes/origin/master
$ git checkout origin/ABCD #### <- Here is the problem!
Note: checking out 'origin/ABCD'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b new_branch_name
HEAD is now at f2bf54a... Clean up README.md
When I press tab after git checkout, for some reason the autocompletion always starts with origin/ and hence a warning message of detached HEAD state.
How can I make the autocomplete not to add 'origin' at the beginning?
|
I found a great plugin for zsh that you can use. If you are using oh-my-zsh then its called gitfast or if just using zsh then you can follow the instructions on his blog article.
As the author details there are in fact quite a lot of git completion issues and his efforts are to resolve them all. This is one issue that now works like the way it does in bash.
https://felipec.wordpress.com/2013/07/31/how-i-fixed-git-zsh-completion/
To enable in oh-my-zsh edit your .zshrc and change the plugins line to add gitfast like so
plugins=(git gitfast)
| zsh git command auto-complete add extra origin to the git branch name |
1,610,403,173,000 |
I have a machine running Ubuntu with a SSH config file in ~/.ssh/config with the following permissions (default when creating a new file)
-rw-rw-r-- 1 dev dev 75 Oct 26 20:13 config
After creating a new user (test) with the same primary group (dev) as the existing user (dev), I am no longer able to git clone when logged in as dev.
dev@vm:~$ git clone ...
Cloning into ...
Bad owner or permissions on /home/dev/.ssh/config
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Googling around seems to suggest that I can fix the ssh problem by running chmod 600 ~/.ssh/config, but why would this even be an issue? How can I fix this systematically, since I assume this would've affected other files too?
Thanks!
|
In the openssh-7.6p1 source code file readconf.c we can see that the permission checking is delegated to a function secure_permissions:
if (flags & SSHCONF_CHECKPERM) {
struct stat sb;
if (fstat(fileno(f), &sb) == -1)
fatal("fstat %s: %s", filename, strerror(errno));
if (!secure_permissions(&sb, getuid()))
fatal("Bad owner or permissions on %s", filename);
}
This function is in misc.c and we can see that it indeed explicitly enforces one member per group if the file is group-writeable:
int
secure_permissions(struct stat *st, uid_t uid)
{
if (!platform_sys_dir_uid(st->st_uid) && st->st_uid != uid)
return 0;
if ((st->st_mode & 002) != 0)
return 0;
if ((st->st_mode & 020) != 0) {
/* If the file is group-writable, the group in question must
* have exactly one member, namely the file's owner.
* (Zero-member groups are typically used by setgid
* binaries, and are unlikely to be suitable.)
*/
struct passwd *pw;
struct group *gr;
int members = 0;
gr = getgrgid(st->st_gid);
if (!gr)
return 0;
/* Check primary group memberships. */
while ((pw = getpwent()) != NULL) {
if (pw->pw_gid == gr->gr_gid) {
++members;
if (pw->pw_uid != uid)
return 0;
}
}
endpwent();
pw = getpwuid(st->st_uid);
if (!pw)
return 0;
/* Check supplementary group memberships. */
if (gr->gr_mem[0]) {
++members;
if (strcmp(pw->pw_name, gr->gr_mem[0]) ||
gr->gr_mem[1])
return 0;
}
if (!members)
return 0;
}
return 1;
}
| Creating a new user breaking existing permissions |
1,610,403,173,000 |
git commit can fail for reasons such as gpg.commitsign = true && gpg fails (for whatever reason). Retrying the command opens a blank editor; the message is lost.
When this happens, is there any way to recover the written commit message, to retry committing with the same message?
|
From man git-commit:
FILES
$GIT_DIR/COMMIT_EDITMSG
This file contains the commit message of a commit in progress. If git commit exits due to an error before creating a commit, any commit message that has been provided
by the user (e.g., in an editor session) will be available in this file, but will be overwritten by the next invocation of git commit.
So, rather than repeat git commit, to retry with the previous message one can use:
$ git commit -m "$(cat .git/COMMIT_EDITMSG)"
Or in general (suitable for an alias for example):
$ git commit -m "$(cat "$(git rev-parse --git-dir)/COMMIT_EDITMSG)")"
| Is git commit message recoverable if committing fails for some reason? |
1,610,403,173,000 |
I'm looking for a way to get three informations from a remote repository using git ls-remote like command. I would like to use it in a bash script running in a cron. Currently, if I do
git ls-remote https://github.com/torvalds/linux.git master
I get the last commit hash on the master branch :
54e514b91b95d6441c12a7955addfb9f9d2afc65 refs/heads/master
Is there any way to get commit message and commit author ?
|
While there is not any utilities that come with git that lets you do what you want, it is rather easy to write a python script that parses a git object and then outputs the author and commit message.
Here is a sample one that expects a git commit object on stdin and then prints the author followed by the commit message:
from parse import parse
import sys, zlib
raw_commit = sys.stdin.buffer.read()
commit = zlib.decompress(raw_commit).decode('utf-8').split('\x00')[1]
(headers, body) = commit.split('\n\n')
for line in headers.splitlines():
# `{:S}` is a type identifier meaning 'non-whitespace', so that
# the fields will be captured successfully.
p = parse('author {name} <{email:S}> {time:S} {tz:S}', line)
if (p):
print("Author: {} <{}>\n".format(p['name'], p['email']))
print(body)
break
To make a full utility like you want the server needs to support the dumb git transport protocol over HTTP, as you cannot get a single commit using the smart protocol.
GitHub doesn’t support the dumb transport protocol anymore however, so I will be using my self-hosted copy of Linus’ tree as an example.
If the remote server supports the dump http git transport you could just use curl to get the object and then pipe it to the above python script. Let’s say that we want to see the author and commit message of commit c3fe5872eb, then we’d execute the following shell script:
baseurl=http://git.kyriasis.com/kyrias/linux.git/objects
curl "$baseurl"/c3/fe5872eb3f5f9e027d61d8a3f5d092168fdbca | python parse.py
Which will print the following output:
Author: Sanidhya Kashyap <[email protected]>
bfs: correct return values
In case of failed memory allocation, the return should be ENOMEM instead
of ENOSPC.
...
The full commit SHA of commit c3fe5872eb is c3fe5872eb3f5f9e027d61d8a3f5d092168fdbca, and as you can see in the above shell script the SHA is split after the second character with a slash inbetween. This is because git stores objects namespaced under the first two characters of the SHA, presumably due to legacy filesystem having low limits on the number of files that can reside in a single directory.
While this answer doesn’t give a full working implementation of a remote git-show command, it gives the basic parts needed to make a simple one.
| Get last commit message, author and hash using git ls-remote like command |
1,610,403,173,000 |
I accidently ran an rm -r on my .git directory. Luckly rm stopped when it got to a write-protected file, but I've still lost several things in my .git.
Files I still have:
FETCH_HEAD
ORIG_HEAD
config
gitk.cache
logs/
objects/
Files I've lost:
HEAD
description
hooks/
index
info/
packed-refs
refs/
From what I can tell, the only things I've lost that I can't re-clone are the changes in my staging area and my refs. I'm prepared to lose my staging changes but I really need to recover my HEAD and my branches. Is there a way to do this? Say, by finding commits that have no children, checking them out to see what they are and creating branches for them? At the moment git doesn't even recognise my repository as a repository anymore though.
|
All of the commits and the files that they reference would be stored as objects
in the objects directory. Git creates those as read-only, so they should all
still be present.
To recover, I'd advise creating a new, empty repository and copying the
contents of your broken repository's objects directory into that of the new
one. That should get you to a point where git will at least recognize that
it's a repository and it will have all of your objects. Working with a copy
will also help to avoid causing even more damage while trying to fix things.
Shell commands to create the temporary repository and copy over the objects:
git init /tmp/recovery
cd /tmp/recovery
cp -r /path/to/broken/repo/.git/objects .git
Once that is done, you could use git fsck to get a list of objects that
aren't referenced by anything. This should include all of the branch heads,
but it would also include any commits that were made obsolete by git commit
--amend or by rebasing.
Since you still have the logs directory that is likely to be an even bigger
help. There should be a logs/refs/heads/<branch> file for each branch that
you had. The second column of the last line will contain the ID of the commit
which was at the head of that branch when the deletion was done. There should
also be logs/HEAD with the same information for where the HEAD was, but
unless you'd been working with a detached HEAD it's probably better to just
recover the branches and then checkout a branch normally.
For each branch that you want to restore you can run:
git branch <name> <commit_id>
Once you've restored the branches you can copy over the config file, and you should be fairly close to where you were as of the latest commit.
| How to recover broken/partially deleted git repository |
1,610,403,173,000 |
Usually, git aliases are confined to a single command:
git config --global alias.ci commit
So, instead of git commit you could do git ci
But it seems you can insert a function in there as well:
git config --global alias.up-sub '!f() { cd $1 && git checkout master && git pull && git submodule update --init --recursive; }; f'
This allows you to call git up-sub some-submodule
The question is: how does it work? I haven't seen the !f() syntax in any other context.
|
Looks like a regular shell function definition and invocation. Only the bang stands out, but a quick search through the git-config(1) manual shows an explanation:
If the alias expansion is prefixed with an exclamation point, it will be treated as a shell command. For example, defining "alias.new = !gitk --all --not ORIG_HEAD", the invocation "git new" is equivalent to running the shell command "gitk --all --not ORIG_HEAD". Note that shell commands will be executed from the top-level directory of a repository, which may not necessarily be the current directory.
Without the bang, it would alias a git subcommand.
| How does this git alias work? |
1,610,403,173,000 |
A history
I installed etckeeper
I decided to track e.g. shorewall firewall configuration as its own git repository. I think I wanted it to be easier to look at specific configuration changes. I decided I did not need etckeeper any more and uninstalled it. So no conflict, except...
While re-considering etckeeper, I notice I didn't actually remove /etc/.git.
Before I realized, I would have thought that git init would refuse to create a nested git repository.
If I simply resumed using etckeeper, I'd be concerned that the outer git could get bloated tracking the inner .git directories. Alternatively, it might ignore all the files in the directories which are separate git repositories.
So I'm curious, what could possibly go wrong?
|
My first tests with nested git repositories didn't suffer any of those three problems. You don't have to add .git in gitignore; the contents of all .git directories are ignored automatically.
The other files (e.g. in the same directory as .git) can be committed in the outer repository.
So I thought etckeeper could keep tracking all files, while sub-directories could have their history recorded more carefully in specific repositories. The two histories wouldn't know anything about each other.
I only noticed a problem later. When I committed a directory which is a git repository and contains commits itself, and I hadn't already committed files from that directory in the outer repository, then it appears as a Subproject. The contents are represented only by a commit ID. gitk seems to show it as a Submodule instead.
This sounds like git really wants to recognize them as git-submodule. I don't particularly understand git-submodule, I just know it has a reputation for being a bit confusing.
I also noticed the .etckeeper file bloats up with files from the .git directories, even if git is using submodules.
| I have nested git repos, will it cause a problem? |
1,610,403,173,000 |
I have a RHEL 6.4 VM provisioned by my company's internal KVM.
We are having some trouble using yum (Cannot retrieve repository metadata, which I've confirmed in this case is peculiar to my company's internal cloud), so I have to build Git from source.
Downloading the RPM file and issuing
sudo yum localinstall ....rpm
Gives me the same Cannot retrieve repository metadata error.
Issuing
sudo rpm -ivh ....rpm
Fails with an error: Failed dependencies and then lists all the packages I need to install. I assume I could find the download links for all of them, but I've tried this before and was unable to find the download links for the right versions for the right packages.
The following code actually works, thanks to @slm's answer:
wget ftp://fr2.rpmfind.net/linux/dag/redhat/el6/en/x86_64/extras/RPMS/perl-Git-1.7.9.6-1.el6.rfx.x86_64.rpm
wget http://pkgs.repoforge.org/git/git-1.7.9.6-1.el6.rfx.x86_64.rpm
rpm -ivh perl-Git-1.7.9.6-1.el6.rfx.x86_64.rpm git-1.7.9.6-1.el6.rfx.x86_64.rpm
If I just download the git code, untar it, and build it, like:
wget https://www.kernel.org/pub/software/scm/git/git-1.8.5.tar.gz
tar -xvf git-1.8.5.tar.gz
cd git-1.8.5
./configure
make
make install
I receive the following error when cloning from the http:// protocol:
fatal: Unable to find remote helper for 'http'
Googling told me that I needed curl-devel and expat. I can not use yum, so I went and built those as well:
cd ..
wget http://curl.haxx.se/download/curl-7.34.0.tar.gz
tar -xvf curl-7.34.0.tar.gz
cd curl-7.34.0
./configure
make
make install
cd ..
wget http://downloads.sourceforge.net/expat/expat-2.1.0.tar.gz
tar expat-2.1.0.tar.gz
cd expat-2.1.0
./configure
make
make install
However, upon rebuilding Git, I receive the same error. After Googling more I determined that I needed to pass the following parameters to Git's ./configure:
cd git-1.8.5
./configure --with-curl=<curl_install_path> --with-expat=<expat_install_path>
However, I couldn't determine where the curl and expat install paths were located.
So what I did instead was build Git, curl, and expat using the ./configure --prefix=/path/to/desired/install/path
mkdir curl
cd curl-7.34.0
./configure --prefix=/home/downloads/curl
...
mkdir expat
cd expat-2.1.0
./configure --prefix=/home/downloads/expat
...
mkdir git
cd git-1.8.5
./configure --prefix=/home/downloads/git --with-curl=/home/downloads/curl --with-expat=/home/downloads/expat
...
and from this I was able to clone with Git from the http protocol. However, this violates the Linux file structure.
Two Questions:
When building Git from source, you need to include the curl and expat install paths to ./configure. Where are these install paths when installing curl and expat without the prefix argument?
I learned that I needed curl and expat's install paths when I got an error and searched for it. Are there any other programs I need to tell Git so I don't get errors in the future?
|
I think I would suggest not installing these items from source directly but rather harness the power of your package manager to still maintain these packages.
locally installing
You can use a command line tool such as curl or wget to still download the packages necessary to install them either using yum or rpm directly.
$ sudo yum localinstall some.rpm
-or-
$ sudo rpm -ivh some.rpm
I would suggest looking to the repositories RepoForge as well as EPEL for RPMs. For example the git packages are here.
http://pkgs.repoforge.org/git/
A simple command in the terminal will download it:
$ wget http://pkgs.repoforge.org/git/git-1.7.10.4-1.el6.rfx.x86_64.rpm
Rebuilding a source RPM
On the off chance you have to have the latest versions, you can still make use of RPMs but rather than download the .rpm version of a package, you'll want to get the .src.rpm version. These can be rebuilt using the following command:
$ rpmbuild --rebuild some.src.rpm
Rebuilding a tar.gz using a donor source RPM
You can also take your .tar.gz tarballs and reuse the .spec file that's included in the above .src.rpm. You do this through the following commands.
$ mkdir -p ~/rpm/{BUILD,RPMS,SOURCES,SPECS,SRPMS,tmp}
Then create a ~/.rpmmacros file.
%packager Your Name
%_topdir /home/YOUR HOME DIR/rpm
%_tmppath /home/YOUR HOME DIR/rpm/tmp
Now we're ready to "install" the donor .src.rpm.
$ rpm -ivh some.src.rpm
This will deposit a tarball and a .spec file in your ~/rpm directories. You can then edit this .spec file and replace the tarball with the newer one.
Now to rebuild it:
$ rpmbuild -ba ~/rpm/SPECS/some.spec
This will create a .rpm and a new .src.rpm file once it's complete.
Additional tips
You can use the tool yum-builddep to make sure you have all the required RPMs installed before getting started.
$ sudo yum-builddep some.src.rpm
| Installing Git, Curl, and Expat from Source |
1,610,403,173,000 |
Using command="" in authorized_keys, I can restrict the commands that can be run by a particular key.
What commands do I need to allow in order to have a functioning git remote?
From the Pro Git book I can infer that git-upload-pack and git-receive-pack are required, but is there anything else?
Note I still want to be able to log into the user normally, just not with this key.
|
Git includes a git-shell command suitable for use as a Git-only login shell. It accepts exactly the following commands:
git receive-pack
git upload-pack
git upload-archive
git-receive-pack
git-upload-pack
git-upload-archive
cvs server (used for emulating a CVS server, and not required for the Git protocol)
So these are the only commands you need to allow. Every version of Git I have access to only uses the hyphenated versions.
git-shell itself may be good enough in itself for what you want to do, too.
You can verify what Git is running for any particular command by setting GIT_SSH to a shim that echoes the arguments. Make a script ssh.sh:
#!/bin/bash
echo "$@" >&2
Then run:
GIT_SSH="./ssh.sh" git push
and you will see the remote command it tried to run.
| What commands does git use when communicating via ssh? |
1,610,403,173,000 |
Every time I try to make my Zsh history file (.zhistory file) a symbolic link to a file (previously existing .zhistory file) that lives in another folder, Zsh deletes the symbolic link and makes it a regular file.
I have tried creating the symbolic link in Bash and then switching back to Zsh, but Zsh will still always remove the link and copy the file instead.
Why is this? How can I have my .zshistory file live somewhere else ? (in my case a git repository not located in the home directory)
|
The easiest way to do this would be to not use links at all. The location of the zsh history file is determined by the value of $HISTFILE. So, to have that backed up, change it from the default value to a file in the watched directory. Add this line to your .zshrc:
HISTFILE=~/foo/.zhistory
Now, copy the existing file over to the new location and any new shell you open should use the new file for saving the history.
| Unable to make .zhistory a symbolic link |
1,610,403,173,000 |
Please forgive me if this seems easy, but I only started learning Unix 2 days ago.
Basically, I have been taught that when typing a command into the terminal it needs to be of the form:
[command name][space][-options][space][arguments]
Now I've just started looking at using git, and I've come across the following:
git config --global core.editor "notepad.exe -wl1"
So in this case is git config the command? How can that work when there is a space in the middle of it? Wouldn't unix get confused and think that config would be an option?
Also just to confuse matters even more, very often I see a command called git-config. Is this the same as git config?
I find it really confusing that in something where precise syntax is very important, these things aren't clearly explained.
|
It is a good starting point, but "generally" needs to be emphasized. For utility commands it is always a good idea to read the man utility page for what is correct syntax.
There is a guideline at The Open Group that can be worth a read. However there is varying level of how conforming implementations are. Some implementations allow one to break this convention, but one should try to heed it as it is both safer and usually more portable (for the day you are on another system with a different implementation.)
When you look at git and quite a few other tools that is not part of the standard utility package one has to learn the way it is done. The use of command is not unique to git but also found in others like pactl / pacmd, amixer etc. As pointed out by @mouviciel this command-based design of git is used by most SCM tools, starting with the old sccs.
program [options] [command] [arguments]
Here often options are geared towards the program itself, and arguments towards the command.
It is a nice way to divide an extended a subset for a main program/suite/tool-kit working within a domain.
domain -verbose DO_THIS -with_file filename.txt
domain -verbose DO_THAT -with_file filename.txt
For some it is also given as a short option and by that adhere to the guidelines like e.g. fdisk -l <device>Enter vs. fdisk <device>Enter, lEnter.
When you execute e.g. git config ... it is not the shell, but git itself
that interpret that config is the command. The use of git-config is more a short way of specifying config as a git command. Try e.g. man git-config. By itself it is usually not recognized as a command.
For git this is also a bit more complex. As it is a tool-kit -> suite, as in many, many commands belonging to git – it is natural to use a command based implementation. This is a design chosen by the developers of git itself.
git DO_THIS
Further. As it holds a lot of commands, they have divided the commands in several groups where the two main is classified as Plumbing and Porcelain. Also see: What does the term porcelain mean in Git?. The manual page has a ordered grouping starting from GIT COMMANDS.
Further one can also customize, trough configuration files, what some of the commands do. As an example. You can view differences between commits by git diff. This command can be customized in your .gitconfig. You can specify which diff program to use and how it should be called.
To make help for various commands easily accessible one also has the possibility to say:
git help command
so git help commit, gives you help for git's commit command.
Guess it could help if you see git as a command line suite, or even a menu driven command environment. As with a GUI application where you can click File->Open->[Some file], a command driven suite could have suite open <file>.
| Bash commands with spaces in them (git config or git-config?) |
1,610,403,173,000 |
I have git configured (like below) to use vimdiff as difftool and compare another pair of files without prompting as soon as I call :qa. It's awesome. The only problem is sometimes there are differences in many files. How do I prevent git from running another vimdiff instance and continuing the diffs queue?
git config --global diff.tool vimdiff
git config --global difftool.prompt false
git config --global alias.d difftool
I tried to quit vim with a non-zero error code (:cq) but it doesn't help.
Would be awesome if the answer worked for both vim and nvim.
|
I found a possible solution from another question, “How do you cancel an external git diff?”
Try running:
git config --global difftool.trustExitCode true
git config --global mergetool.trustExitCode true
and then exiting with the non-zero :cq.
| How to prevent `git difftool` from calling another `vimdiff`? |
1,392,755,257,000 |
How can I produce a list of filenames (incl. paths) that git knows about over the course of the whole history?
|
Naive solution:
git rev-list --all | xargs -n1 git ls-tree --full-name -r --name-only | sort -u
This lists all commits, then uses that to list all files in every commit. sort deduplicates. Only works for small-ish repos though as it takes a long time.
A better solution would be to use libgit2 to do the same, should be faster but requires some programming. A quick hack that implements this can be found on github. It uses pygit2 and is an order of magnitude faster than the shell pipeline above.
| How to show all files git knows about? |
1,392,755,257,000 |
I occasionally need to grep through git submodules for which I use:
git submodule foreach 'git grep x'
However, since switching to zsh I find a less prompt is opened for each submodule, even when there are no options. What I'd much prefer is for all of the output to be printed out to the terminal.
My current solution is to call:
git submodule foreach 'git grep x' > /tmp/a && cat /tmp/a
Which achieves what I want but I can't help but feel that I'm missing an option or a more elegant solution. Is there one?
|
Try changing the pager that git uses:
GIT_PAGER="cat" git submodule foreach 'git grep x'
Or if you want less to be used, but only when output will run off of the screen:
GIT_PAGER="less -FX" git submodule foreach 'git grep x'
You can set the pager per project by using git config, or you can, of course, set the environment variables globally.
| Stop Git submodule foreach from opening less for each module |
1,392,755,257,000 |
Long story short: I've used only distributions with "imperative configuration management/packaging" approach, so far. And,... I'm annoyed by hard to trace breakages/issues with imperative configuration management (when experimenting).
I've found NixOS, which advertises:
NixOS has a completely declarative approach to configuration management: you write a specification of the desired configuration of your system in NixOS’s modular language, and NixOS takes care of making it happen.
I'm considering to use NixOS as my main desktop operating system, and store configuration in GIT repository.
So, is NixOS configuration gittable? Can I "define" my main operating system configuration by git repository (proabbly with some "apply" commands)?
|
The NixOS configuration consists of two files (although you can break it up into more files): configuration.nix and hardware-configuration.nix.
Both files are stored in /etc/nixos and they are text files. Hence, you can certainly put them in a GIT repo.
| Can I manage my NixOS configuration in version control like git? |
1,392,755,257,000 |
I'm running bash
GNU bash, version 4.3.25(1)-release (x86_64-apple-darwin13.4.0)
on OS X 10.10.1. A week or so ago I've noticed that autocompletion has stopped working, but only for git. I'm using this script for git autocompletion:
https://github.com/git/git/blob/master/contrib/completion/git-completion.bash
Few days after it has stopped working, I've noticed that autocompletion still works for commands starting with letter 's' (e.g. status, show, stash). After that I've tried to autocomplete this command:
git c
and here's the output:
user:~$ git c^[[m^[[K
c^[[m^[[Kat-file
c^[[m^[[Kheck-attr
c^[[m^[[Kheck-ignore
c^[[m^[[Kheck-mailmap
c^[[m^[[Kheck-ref-format
c^[[m^[[Kheckout
c^[[m^[[Kheckout-index
c^[[m^[[Kherry
c^[[m^[[Kherry-pick
c^[[m^[[Kitool
c^[[m^[[Klean
c^[[m^[[Klone
c^[[m^[[Kolumn
c^[[m^[[Kommit
c^[[m^[[Kommit-tree
c^[[m^[[Konfig
c^[[m^[[Kount-objects
c^[[m^[[Kredential
c^[[m^[[Kredential-cache
c^[[m^[[Kredential-osxkeychain
c^[[m^[[Kredential-store
c^[[m^[[Kvsexportcommit
c^[[m^[[Kvsimport
c^[[m^[[Kvsserver
As you can see, some strange (escape?) characters are inserted after the first letter of each command (the same happens for all other letters other than 's'). Because of those characters, autocompletion isn't working as expected.
Does anyone have an idea of what could cause this? I do not even know how to debug this, so any tips are welcome.
|
These strange escape sequences are color-changing commands.
The completion code runs the following command to list available commands:
git help -a|egrep '^ [a-zA-Z0-9]'
The output of git help -a looks like this:
add grep remote
add--interactive hash-object remote-ext
am help remote-fd
…
fsck-objects receive-pack write-tree
gc reflog
get-tar-commit-id relink
If grep is configured to print the matching part of the line in color, then command names that are in the first column will have their first letter highlighted:
$ git help -a|egrep --color=always '^ [a-zA-Z0-9]' | cat -v | head -n 1
^[[01;31m^[[K a^[[m^[[Kdd grep remote
When bash sees this output, it thinks that ^[[01;31m^[[K, a^[[m^[[Kdd, grep and remote are possible commands. The first one won't turn up, the last two are correct, the second one is mangled.
You need to configure grep not to use colors when its output is not on a terminal. If you've aliased egrep to egrep --color=always (and ditto for grep and fgrep), change that to --color=auto. If you've set the GREP_OPTIONS variable somewhere, change --color=always to --color=auto there.
| Strange characters in GIT completion |
1,392,755,257,000 |
I have an SSH server running on my Raspberry PI with ALARM (up to date).
My user "gitroot" is meant to use the git-shell. However, when I set /usr/bin/git-shell as shell for gitroot in /etc/passwd, I can't login with that user anymore. su - gitroot works as expected. When I change the shell to /bin/bash, I can login as gitroot via ssh.
The permissions of /usr/bin/git-shell and /bin/bash are the same. I tried changing the password, it didn't change anything. Output from journalctl -f:
Jul 23 09:05:27 netberry sshd[4213]: pam_unix(sshd:auth): authentication failure;logname= uid=0 euid=0 tty=ssh ruser= rhost=localhost.localdomai...r=gitroot
Jul 23 09:05:40 netberry sshd[4213]: Failed password for gitroot from 127.0.0.1 port 51969 ssh2
Jul 23 09:07:25 netberry sshd[4213]: Connection closed by 127.0.0.1 [preauth]
Jul 23 09:07:29 netberry sshd[4222]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=localhost.localdomai...r=gitroot
Jul 23 09:07:43 netberry sshd[4222]: Failed password for gitroot from 127.0.0.1 port 51970 ssh2
Jul 23 09:08:07 netberry sshd[4222]: Failed password for gitroot from 127.0.0.1 port 51970 ssh2
Jul 23 09:08:08 netberry sshd[4222]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=localhost.localdomai...r=gitroot
Jul 23 09:08:10 netberry sshd[4222]: Failed password for gitroot from 127.0.0.1 port 51970 ssh2
Jul 23 09:08:10 netberry sshd[4222]: Connection closed by 127.0.0.1 [preauth]
The log shows multiple attempts to log in as gitroot over ssh from the host itself (I just typed ssh gitroot@localhost into the console).
|
As mentioned in the comments, you should add /usr/bin/git-shell to /etc/shells.
| SSH: "Permission denied" after changing user shell |
1,392,755,257,000 |
I'm trying to setup a linter for my code and I only want to lint the coffeescript files that have changed in the current branch. So, I generate the list of files using git:
git diff --name-only develop | grep coffee$
That gives me a nice list of the files I'd like to process but I can't remember how to pipe this to the linting program to actually do the work. Basically I'd like something similar to find's -exec:
find . -name \*.coffee -exec ./node_modules/.bin/coffeelint '{}' \;
Thanks!
|
xargs is the unix utility I was looking for. From the man page:
The xargs utility reads space, tab, newline and end-of-file delimited strings from the standard input and executes utility with the strings as arguments.
Any arguments specified on the command line are given to utility upon each invocation, followed by some number of the arguments read from the standard input
of xargs. The utility is repeatedly executed until standard input is exhausted.
So, the solution to my original question is:
git diff --diff-filter=M --name-only develop | grep coffee$ | xargs ./node_modules/.bin/coffeelint
| How can I pipe stdout to another program? |
1,392,755,257,000 |
I am trying to install git on my Red Hat Enterprise Linux 6.5 server and have hit a brick wall. I can't find the package dependencies for git using yum.
[root@FOOBAR mydir]# yum install curl-devel expat-devel gettext-devel \
> openssl-devel zlib-devel
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Setting up Install Process
No package curl-devel available.
No package expat-devel available.
No package gettext-devel available.
No package openssl-devel available.
No package zlib-devel available.
Error: Nothing to do
After reading a few forum posts, I found the EPEL package here, and installed it:
[root@FOOBAR mydir]# rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
Retrieving http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
warning: /var/tmp/rpm-tmp.IlnMHM: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Preparing... ########################################### [100%]
1:epel-release ########################################### [100%]
however even after this i still get the same error. can someone please help me out?
UPDATE: The output of yum repolist:
[root@FOOBAR ~]# yum repolist
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
repo id repo name status
epel Extra Packages for Enterprise Linux 6 - x86_64 10,657
repolist: 10,657
UPDATE2: I changed the /i386/ to /x86_64/ because i erased the i386 one and replaced it with epel 64 bit repo.
|
It seems that you didn't register with RHN, so you are unable to download from Redhat's base repo.
You can't get Redhat official packages without registering.
If you don't have RHN credentials, you can use the Centos base repo instead. See this link for more details.
| No package * available. cannot install git through yum |
1,392,755,257,000 |
I have some markdown files but I can't git diff them.
No result at the command line and not supported in gitg (visual git)
Is that possible with the files as they are, without converting them to something else?
|
It should work fine; markdown files are plaintext files, so git diff is perfect.
This could be one of a few possible things:
There is no difference in the file (empty output).
The changes to the files have not been added (git add -p *.md)
What does git status say? If it doesn't contain a few lines that say something like "modified: something.md" or "new file: something.md" then you're not going to get a diff.
EDIT: These files are actually in a git repo right? If not, just use Unix's normal diff utility (man diff for more info).
| How can I git diff markdown (.md) files |
1,392,755,257,000 |
The vc bundle is a neat little package that extracts information about a git repo for easy insertion into a LaTeX document. It doesn't currently extract information about whether the current commit is tagged and what the tag name is. How would I edit the vc script to do this?
And then how would I edit the vc-git.awk script to add an extra line to the generated vc.tex file? Presumably I want a line that looks like:
print "\\gdef\\GITTag{" Tag "}%"
but I need an earlier line that tells awk what " Tag " means?
This isn't a question about LaTeX, it is about git, awk and bash...
|
git log --decorate -1 [commit]
If commit (HEAD if omitted) has tags, the commit hash will be followed by (tag: name) (and possibly multiple other symbolic references too). You can pick this out more specifically with
git log --pretty=%d
| extracting "tag" information from git with a shell script |
1,392,755,257,000 |
Can I display GIT in prompt when current directory has/contains a .git folder? Is there a way to do this? My current prompt is defined like so:
export PS1="[\u@\h] \w $ "
So, my prompt looks like this:
[user@computer] ~/workspace $
And I want it to dynamically look like this:
[user@computer] ~/workspace GIT $
|
The most standard way is to use __git_ps1 directly from git. In Ubuntu, it is available in this path:
source /usr/lib/git-core/git-sh-prompt
## source /etc/bash_completion.d/git-prompt
#PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w $(__git_ps1 "(%s)")\$ '
You can notice the added part $(__git_ps1 "(%s)"), which will notify you about the current state of repo -- current branch, ongoing rebases, merges and so on.
The file in Ubuntu is provided by git package:
$ dpkg-query -S /usr/lib/git-core/git-sh-prompt
git: /usr/lib/git-core/git-sh-prompt
For fedora by git-core (with a bit different path):
rpm -qf /usr/share/git-core/contrib/completion/git-prompt.sh
git-core-2.5.5-1.fc23.x86_64
Your prompt will change from
[user@computer] ~/workspace $
to
[user@computer] ~/workspace (master)$
| Can I display GIT in prompt when current directory has a .git folder? |
1,392,755,257,000 |
If I install a git-package via packer or pacaur, then it will pull the current source-tree of the repo, compile, and install it.
But how are updates handled? Is there a specific way to upgrade all my AUR-Git Packages?
|
In addition to jasonwryans excellent answer: Most AUR helpers have a flag to update development packages, even if their pkgver hasn't changed in the AUR. For pacaur, that flag is called --devel which can be used in conjunction with its update operations. It will cause pacaur to rebuild development package, but only if their source is newer than that of the already installed package. Supplying the --rebuild option as well will make pacaur rebuild development packages even if your current package is up to date.
| How package managers update packages installed using git-packages? |
1,392,755,257,000 |
I have a bunch of raspberry pis running Ubuntu 20.04 server, that I wish to update automatically via Git, non-interactively.
The script does the following:
eval "$(ssh-agent -s)" ; ssh-add /home/michael/.ssh/terminal_github_deploy_key ; git -C /home/michael/terminal/src pull
The script is actually in Python, but does the equivalent to above:
cmds = []
cmds.append('eval "$(ssh-agent -s)"')
cmds.append(f'ssh-add {HOME_DPATH}/.ssh/terminal_github_deploy_key')
cmds.append(f'git -C {CHECKOUT_DPATH} pull')
cmd = ' ; '.join(cmds)
subprocess.check_call(cmd, shell=True)
It works fine except it raises this interactive warning:
The authenticity of host 'github.com (140.82.121.3)' can't be established.
ECDSA key fingerprint is SHA256:...
Are you sure you want to continue connecting (yes/no/[fingerprint])?
According to research it deliberately does not accept pipes for security reasons (so yes | ... does not work). I am not sure what is raising the warning, I am guessing it's SSH, being called by Git, but not sure how to ignore it? I don't have to use ssh-add but that was the way I managed to get it working.
|
Without writing another script in something like expect, you will not be able to do that while being vanilla.
The easiest way to do so is to add the Github Host Keys to
.ssh/known_hosts
EDIT: Due to the fact that there is a lot of servers, this is not possible, what is on that site is not individual host keys
Otherwise, you may be able to use GitPython to automate that
| Automate git pull with ssh authentication via a script (non-interactive) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.