date int64 1,220B 1,719B | question_description stringlengths 28 29.9k | accepted_answer stringlengths 12 26.4k | question_title stringlengths 14 159 |
|---|---|---|---|
1,428,000,262,000 |
I am using git to version control config files on my system. I have git root at the root of my filesystem /, and I control /etc and /root.
When I am in /root and do: git log .zshrc, it shows me commit history. I want to display the contents of .zshrc for particular commit:
# git show a100e3515779a900509b52230d449a6446fa110b:.zshrc
fatal: Path 'root/.zshrc' exists, but not '.zshrc'.
Did you mean 'a100e3515779a900509b52230d449a6446fa110b:root/.zshrc' aka
'a100e3515779a900509b52230d449a6446fa110b:./.zshrc'?
# git show a100e3515779a900509b52230d449a6446fa110b:/root/.zshrc
fatal: Path '/root/.zshrc' exists on disk, but not in
# git show a100e3515779a900509b52230d449a6446fa110b:root/.zshrc
# git show a100e3515779a900509b52230d449a6446fa110b:./.zshrc
only the last 2 commands works. Why do .zshrc and /root/.zshrc not work, and why do I have to use the least convenient notation such as ./.zshrc ?
Is there some configuration option that I can change, so that git understands .zshrc and /root/.zshrc ?
|
In <rev>:<path> notation, the path is relative to the tree-ish object itself, not to the current directory, unless it starts with ./ or ../. In both cases absolute paths (…:/…) aren’t supported, only relative paths.
git show a100e3515779a900509b52230d449a6446fa110b:.zshrc
means “find the a100e3515779a900509b52230d449a6446fa110b object, and inside that object, show me the .zshrc file”. Think of a100e3515779a900509b52230d449a6446fa110b as an archive of sorts; it exists independently of your current directory, and has no notion of your current directory.
As far as I’m aware there’s no configuration option you can change to get git show to understand .zshrc as ./.zshrc in this context.
See the gitrevisions documentation for details.
| git show does not understand relative file names |
1,428,000,262,000 |
From May 30, 2022:
Google no longer supports the use of third-party apps or devices which ask you to sign in to your Google Account using only your username and password.
This is a problem for various applications including git send-email. sendgmail is tool from Google written in go which allows to use OAuth2 credentials.
Using sendgmail requires certain configuration in Google Cloud, download JSON with configuration and rename to ~/.sendgmail.json and then run once:
$ GOPATH/bin/sendgmail [email protected] -setup
1. Ensure that you are logged in as [email protected] in your browser.
2. Open the following link and authorise sendgmail:
https://accounts.google.com/o/oauth2/auth?...
3. Enter the authorisation code:
My ~/.sendgmail.json contains redirect_uris":["http://localhost"], therefore clicked website is redirected to localhost (no webserver is on my machine) and I don't get the authorisation code. Could anybody explain what exactly to do in Google Cloud setup to get it working?
|
Setup the Workspace by following these steps.
Enable the Gmail API on the project.
Setup the OAuth Consent Page.
I'm not sure if you can get past not having an authorized domain. I included one I own (and use for a different Google OAuth workflow)
Ensure the Gmail API ../auth/gmail.send scope is allowed, nothing else seems required.
Include yourself as a registered test user.
Create Credentials.
Type: OAuth Client ID
Application Type: Desktop App (others may work, just following linked guidance)
Install the sendgmail go package: go install github.com/CyCoreSystems/gmail-oauth/sendgmail@latest
Run the setup command as you've included.
Follow the instructions to authenticate and be redirected to the non-functional page (due to the redirect_uri being localhost.)
The authorization code you need to enter in the prompt can be scraped from the URL for that non-functional redirect.
Here is a example of the URL, you'll need the value of code GET parameter (i.e. the entire string after code= and before &scope):
http://localhost/?state=state&code=foobarauthcode&scope=https://mail.google.com/
The tool doesn't seem to output anything after submitting the authorization code, however testing sending a patch file to myself was successful with:
git send-email --smtp-server=$GOPATH/bin/sendgmail [email protected] patch-test.diff
| gmail sendgmail configuration for git send-email |
1,428,000,262,000 |
I build openwrt firmware and I just used a pr (patch kernel update) with patch -p1 < filename.patch and I want to remove to reapply a new one, what would be the best?
thank you
|
You can revert the patch:
patch -R -p1 < filename.patch
| removing last patching kernel |
1,428,000,262,000 |
I have this ~/.gitconfig alias:
b = "!r() { count=10; git for-each-ref --sort=-committerdate refs/heads --format='%(HEAD)%(color:bold green)%(committerdate:relative)|%(color:yellow)%(refname:short)|%(color:red)%(objectname:short)%(color:reset)|%(color:blue)%(subject)|%(color:magenta)%(authorname)%(color:reset)' --color=always --count=${count:=10} | column -c 10 -ts '|'; }; r"
My issue with this function is that it formats the string based on the longest row, i.e. if I have a table with the following values (This is not the output from git branch --format, just an example to illustrate column behavior):
a, b, c
x, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy, z
then it will look like
a, b , c
x, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy, z
This is a good behavior which column is responsible to, however I want to trim the string length, so, for example, no column will be longer > 4:
a, b , c
x, yyyy, z
I managed to add a piped awk to do something like that (used 25 chars):
b = "!r() { count=10; git for-each-ref --sort=-committerdate refs/heads --format='%(HEAD)%(color:bold green)%(committerdate:relative)|%(color:yellow)%(refname:short)|%(color:red)%(objectname:short)%(color:reset)|%(color: blue)%(subject)|%(color:magenta)%(authorname)%(color:reset)' --color=always --count=${count:=10} | column -c 10 -ts '|' | awk '{for(i=1;i<NF;i++){$i=substr($i,1,25)}; print $0}'; }; r"
but it messes up the table :(
It also misbehaves with the * in the start of the current branch.
How can I fix this?
I tried to install a newer version of column which should have a -c option to control width but I couldn't :( (downloaded from here and then tried to ./configure && make install. Didn't work as expected).
Tried to format the function with \ and newlines - didn't work. Must gitconfig functions look so ugly?
$ git --version
git version 2.34.1
|
If you don't have access to a column implementation that understands output width limitation, one way would be to implement the "column-building" algorithm in awk. However, implementing the logic - while straighforward - adds quite a bit to the length of your gitconfig function:
awk -F'|' -v maxw=4 '{for (i=1;i<=NF;i++) {l=length($i); if (l>maxw) l=maxw; if (l>mw[i]) mw[i]=l; lines[NR]=$0}}
END{for (j=1;j<=NR;j++) {n=split(lines[j],f,/\|/); for(i=1;i<=n;i++) {printf("%*s%s",mw[i],substr(f[i],1,maxw),i==n?ORS:OFS)}}}'
As you can see, this awk program splits the input on the | (which is what you stated to be the actual output of the git branch command).
For each line it iterates over all fields and stores the maximum field width in an array mw for each column, but limited to the maximum width as specified in the variable maxw.
It then stores the "original" content of each line (including the original field separators) in a buffering array lines.
At end-of-input, it iterates over the lines buffer and splits the line again at the | into an array f. For each entry of f, it prints at most maxw characters of the field via printf, where the desired field width is taken from the mw array for the respective column.
For your example (but assuming the actual |-separation instead of the , you showed), the output would be:
a b c
x yyyy z
| How to limit git branch --format string length |
1,428,000,262,000 |
I am new to linux, and I have just installed git using,
sudo apt-get install git-all
When I attempted to restore a file after making modifications, I get the following error:
git: 'restore' is not a git command. See 'git --help'.
I did some research, and it turns out that git restore was not implemented until git version 2.23.0. I then ran,
git --version
And saw that I had 2.20.1 installed. To update git, I ran,
sudo apt-get update
sudo apt-get --only-upgrade install git-all
It told me that git-all is already the newest version (1:2.20.1-2+deb10u3), but this is not the latest version of git. The latest version of git is 2.34.1. What is happening here and how can I update git?
|
You can download the latest version here:
https://git-scm.com/download/linux
URL: https://www.kernel.org/pub/software/scm/git/git-2.34.1.tar.gz
then make it.
| Git is not updating [duplicate] |
1,428,000,262,000 |
Let's suppose the following scenario, two Linux computers A and B are connected through an special hardware radio link, which is not always available. This might be the case with two Raspberry Pi. None of the computers have access to the internet.
Linux A has a library called libabc.so with a size of 1GB and Linux B has the source code of that same library. Let's say some user in Linux B changes a single constant in the source code and recompiles the library.
Is there any way or tool to send the updates from Linux B to Linux A without sending the whole 1GB recompiled file ?
I was thinking of using git somehow, but it does not store incremental changes for non text files. As far as I understand rsync will synchronize the whole file as well. In both cases I cant access the filesystem in the other computer with the radio link easily anyway. So in both cases a 1GB of data will be sent. Another solution would be cloning and updating source code on Linux A but compilation takes time and Linux B has much better performance.
The last solution would be writing a lightweight tool like this myself. But I'm suspecting there is already something available.
|
As far as I understand rsync will synchronize the whole file as well.
It will synchronize the file. But the default behavior (for network transfers) is not to send the entire data if the file already exists, but to calculate and compare rolling block checksums. This reduces the data that has to be sent if there is commonality.
From How Rsync Works A Practical Overview
If a file is not to be skipped, any existing version on the receiving
side becomes the "basis file" for the transfer, and is used as a data
source that will help to eliminate matching data from having to be
sent by the sender. To effect this remote matching of data, block
checksums are created for the basis file and sent to the sender
immediately following the file's index number.
...
If a block checksum match is found it is considered a matching block
and any accumulated non-matching data will be sent to the receiver
followed by the offset and length in the receiver's file of the
matching block and the block checksum generator will be advanced to
the next byte after the matching block.
| Update a library file with just the changes in the new file |
1,428,000,262,000 |
I'm using git-annex in version 7.20190129 as it is provided on my Debian Stable (Buster) machine to keep big files under version control and have them distributed over multiple machines and drives. This works well as long as I have at least one "real" git-annex repository (not a special remote).
What I'd be interested in is using just one git annex repository on my local machine and additionally special remotes (e.g. the bup special remote or the rsync special remote or, as soon as it lands on Debian Stable, the borg special remote).
My workflow is as follows:
cd /path/to/my/local/folder
git init
git annex init
git annex add myawesomefile
git commit -m 'this works on my local repository'
git annex initremote mybupbackuprepo type=bup encryption=none buprepo=/path/to/my/special/remote/location
git annex sync
git annex copy files --to mybupbackuprepo
Then I'm able to use my bup special remote as I would use an additional repository.
But now I'd like to access my bup repo without using the first, local repo (e.g. in case my local machine would break down). As far as I understood (from following the official guide, the following should work:
cd /path/to/new/folder/to/extract/the/backup
git init
git annex init
git annex initremote mybupbackuprepo type=bup encryption=none buprepo=/path/to/my/special/remote
git annex enableremote mybupbackuprepo
git annex sync
But I'm still not able to see any files (or even some broken symlinks) and, obviously, also not able to get any of my data when using git annex sync --content or git annex get myawesomefile.
Any ideas? What am I missing?
|
A special remote is just storing the file data, not the git repository. Think of it as a a library's cellar: A library may build an additional room to store its books there, but if you want to build a library back from the cellar, you don't have any index, don't know which book is in which catalogue, and you don't have a librarian that can help you find your books.
So in practice, you will need another git repository to replicate the master branch, which contains all the information about what goes where.
In cases like yours (where you host that storage yourself), you don't need any special remote then -- the regular (typically but not necessarily bare) git repository you use as your origin can also store the large files, and can be used by a later checkout just as
$ git clone ssh://host/path/repo
$ cd repo
$ git annex init
$ git annex get --from origin
(where the --from origin is more for illustration; if you leave it off, git annex will know what to do as well).
In many cases you don't even need a special remote then; reasons to use a special remote are:
You want to split the (small but often needed) git access from data access (large amounts of data), and your data hoster gives you just rsync (or webdav or s3 or whichever protocol) access, not full shell access
Your git hoster gives you just bare git, and does not have git-annex installed (eg. GitLab) -- then you need an extra data hoster
You need any special properties of the backend (like deduplication across repositories, which only works as long as you don't use encryption)
In most cases (like, it seems, yours), just using a regular git remote and annex-copying data there is just as good, less a hassle to set up, and most importantly you need one anyway to recover your data.
| accessing git-annex special remote from new repository |
1,428,000,262,000 |
I'm running git fsck command on some repositories, and for 4 of them I got the same error:
error in tree b2b510c83ea553c587ebe5bc160e92cb7888393a: duplicateEntries: contains duplicate file entries
error in tree b3969ac6fe6b6359d48006e6a4cf3ffd5a4350a3: duplicateEntries: contains duplicate file entries
error in tree 5a7445940626358083a782ba5c81f956c7f82ac5: duplicateEntries: contains duplicate file entries
any idea how to fix it? what does it mean that it appears exactly the same for all?
|
Git stores the contents of a directory in a tree object. In general, tree objects are supposed to be in sorted filename order by byte value.
This message means that those particular tree objects contain a duplicate entry, which isn't supposed to be the case. Whatever tool you're using to create these objects has created corrupt ones, and Git is now complaining.
To fix it, you should first stop using whatever tool created these problems so you don't make it worse. Then, you can run git gc --prune=now to delete unused objects immediately. You can then run git fsck to see if the commits are gone; if they're not in the history, they'll have been deleted.
If this doesn't work, then you can rewrite the repository by creating a new repository and running something like the following:
git fast-export --all | (cd /empty/repository && git fast-import)
This will necessarily rewrite some of your object IDs, but Git will not import the duplicate values when it writes the new repository.
| git fsck fails with the same error for 4 different repositories |
1,428,000,262,000 |
If I run a command in a subshell, I can collect the stdout into a variable, such as:
var=$(echo 'hello world')
echo $var
Will print 'hello world' as expected.
If I add colour and a new line, this too is ok:
var=$(echo "Text in \n\e[34mBlue")
echo -e $var
Prints "Text in Blue" with the word 'Blue' coloured and on the next line as expected.
However if I try this with git output, such as
var=$(git status)
echo $var
It loses all the newlines and colouring.
How can I capture the output of a git command and print it later on, while preserving formatting and colouring in bash?
|
The default value of git's color.ui configuration is auto, which only uses colours when output is to a TTY. You can change that in your configuration to always to have the output be coloured regardless.
Most usefully for your use case, there is a -c option to git that allows overriding a configuration value just for the current command. You can use that to set color.ui to always:
var=$(git -c color.ui=always status)
printf '%s\n' "$var"
Note though that in your second example
var=$(echo "Text in \n\e[34mBlue")
echo -e $var
it's actually the echo -e line that causes the colours to appear - the escape codes weren't interpreted by the echo inside the command substitution, and the backslashes and other characters were literally there. It wasn't that the colour codes were stored that time and forgotten when they came from git - they were created at the end in one case, and never at all in the other.
| Capture git output into variable |
1,428,000,262,000 |
I have found a strange error. It is OK when I commit using gpg with git under bash or zsh.
git commit -S -m "xxx"
However when I commit it under tmux, I got:
gpg: signing failed: Operation cancelled
gpg: signing failed: Operation cancelled
error: gpg failed to sign the data
fatal: failed to write commit object
|
You need to ensure that your GPG_TTY variable is correct; add
GPG_TTY=$(tty)
export GPG_TTY
to your shell startup scripts, including for non-login shells (your login shells are probably OK, but not non-login shells, which is why this fails in tmux).
| gpg: signing failed: Operation cancelled under tmux? |
1,428,000,262,000 |
I have a weird issue that I can't seem to find an answer for.
When I enter:
git config --global http.proxy http://{username}:{password}@{proxy address}:{port}/
It returns an error:
git config --global http.proxy http://{username}:mount /dev/cdrom /media/cdrom{password}@{proxy address}:{port}/
I do have an !1 in the password field that seems to be getting replaced and the rest of the password is echoing.
I had a look is !1 is a shortcut to /dev/cdrom but couldn't find anything.
|
Yes, in an interactive shell, ! is the last command line, and it's quite possible !1 is the first word of it, etc. (Can you tell it's not a feature I use?) Just put the whole proxy url in single quotes like
git config --global http.proxy 'http://{username}:{password}@{proxy address}:{port}/'
(You'll see similar effects with $ and anything that's a shell wildcard like ? or *: the command line doesn't know what's a file name parameter.)
| Proxy address is being replaced with /dev/cdrom |
1,428,000,262,000 |
In my .bash_profile I have a parse_git_branch function from the internet, and a PS1 to color some of my output.
If possible, I would like to make my git branch name colored red, instead of white.
I tired changing a few variables, but with no luck. I would like (master) to be red, if possible.
|
I was able to get the git branch to print out in red by changing
export PS1="\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[93m\]\w\[\033[m\]\$(parse_git_branch)\[\033[00m\] \n$ "
to
export PS1="\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[93m\]\w\[\033[31m\]\$(parse_git_branch)\[\033[00m\] \n$ "
To highlight the specific change was using [31m\]\$(parse_git_branch) instead of [m\]\$(parse_git_branch)
| Changing the color of git branch output? |
1,428,000,262,000 |
I created a list by using
$ git stash show --name-only | grep -i "Kopie"
Output:
A - Kopie.txt
B - Kopie.txt
How can I unstash all the files from the list?
First Approach:
$ git stash show --name-only | grep -i "Kopie" | xargs git checkout stash@{0} --
Result:
error: pathspec 'A' did not match any file(s) known to git.
error: pathspec '-' did not match any file(s) known to git.
error: pathspec 'Kopie.txt' did not match any file(s) known to git.
error: pathspec 'B' did not match any file(s) known to git.
error: pathspec '-' did not match any file(s) known to git.
error: pathspec 'Kopie.txt' did not match any file(s) known to git.
|
You are not quoting the filenames when they are passed to git checkout, so A, - & Kopie.txt are being treated as different files.
Try adding the -I {} option to xargs, then put quotes around {}:
git stash show --name-only | grep -i "Kopie" | xargs -I {} git checkout stash@{0} -- "{}"
| Git unstash all files from list |
1,428,000,262,000 |
Is there a straightforward way to display the results of my PS1 for a given set of directories?
To avoid the XY Problem, I'll state up front: I want to rapidly check the status of every git repo within a directory. I can run git status in a for ... do ... done loop, but that is hard to read.
I have oh-my-git running beautifully as part of my command prompt and it displays the status I'd like to know at a glance. I'd like to see what it says for every sub-directory in my repos directory.
I can see what I need by manually calling cd ~/repos/first-repo followed by the next, but besides the repetitive typing, I also have to remember all of the repos without skipping one. I'd be happy to script out cding into each repo and displaying my customized prompt.
|
for rep in */; do
printf '%s:\t' "$rep"
( cd "$rep" && git status --short --branch --untracked-files=no )
done
or, using short options,
for rep in */; do
printf '%s:\t' "$rep"
( cd "$rep" && git status -sbuno )
done
This changes into each directory in the current directory and runs the given git status command. The output may look something like
gnomad_browser/: ## master...origin/master
swefreq-browser/: ## gnomad-remerge...origin/gnomad-remerge
swefreq-config/: ## develop...origin/develop
swefreq/: ## feature/schema-update...origin/feature/schema-update
M sql/swefreq.sql
(I have an uncommitted file in the swefreq repository)
The options picked for git status here will show just the current branch and any modified files, but you could easily modify it to show untracked files as wull by removing -uno or --untracked-files=no.
See git status --help.
Your idea of using the prompt to show you info about each directory may work depending on how your prompt is set up. My prompt is a single-quoted string that must be evaluated:
for rep in */; do
( cd "$rep" && eval echo "$PS1" )
done
I do not think that this is a very nice solution, and it's also not very flexible in what it can do and tell you about each repository.
| Display command prompt (PS1) info for a set of directories |
1,428,000,262,000 |
I have several Git repositories containing a file mergedriver.info
This file looks always like this:
<project name>
<repository name>
A script, triggered by a Git merge driver, is evaluating this file:
mergedriverinfo="$(git cat-file -p HEAD:mergedriver.info)"
success=$?
if [[ "$success" == "0" ]]; then
log "Evaluating mergedriver.info"
PROJECT_KEY="$(sed -E 's/([^\s]+)\s+([^\s]+)/\1/' <<< $mergedriverinfo)"
REPO_SLUG="$(sed -E 's/([^\s]+)\s+([^\s]+)/\2/' <<< $mergedriverinfo)"
log "PROJECT_KEY=$PROJECT_KEY"
log "REPO_SLUG=$REPO_SLUG"
else
log "Unable to read mergedriver.info"
exit 1
fi
I don't understand the behaviour of sed in this case.
For this mergedriver.info:
test
conflict-on-auto-merge
The log output looks like this:
2017-07-20 11:05:51.747 PROJECT_KEY=test
2017-07-20 11:05:51.748 REPO_SLUG=tesconflict-on-auto-merge
At first I tried reading the mergedriver.info with sed -n 1p/2p and head/tail -1, but unfortunately the output of $(git cat-file -p HEAD:mergedriver.info) is different for two different platforms on which this script is running:
Platform 1:
$ od -c <<< $(git cat-file -p HEAD:mergedriver.info)
0000000 t e s t \n c o n f l i c t - o n
0000020 - a u t o - m e r g e \n
0000034
Platform 2:
± od -c <<< $(git cat-file -p HEAD:mergedriver.info)
0000000 t e s t c o n f l i c t - o n
0000020 - a u t o - m e r g e \n
0000034
How to solve this problem?
|
You need to realize that the sed regex [^\s] will not do what you think it should, viz. hunt for a non-whitepspace, rather it shall negate two characters, a backslash \ and the letter s.
What is needed is the \S which is meant specifically for this.
And to manage the output of mergerdriver.info command spilling over multiple lines is the N command from sed's toolbox.
PROJECT_KEY=$(sed -nEe '$!N;s/(\S+)\s+(\S+)/\1/p' <<<"$mergedriverinfo")
REPO_SLUG=$(sed -nEe '$!N;s/(\S+)\s+(\S+)/\2/p' <<<"$mergedriverinfo")
| Extracting parts of whitespace separated string |
1,497,883,180,000 |
I have a Drupal 8 installation in a directory called my-D8. I want to update it to drupal 8.3.1, and I've downloaded drupal-8.3.1.tar.gz. I have both in my sites directory:
/d/sites $ ls
drupal-8.3.1.tar.gz my-d8/
When I try to extract the archive, it puts everything in a directory called drupal-8.3.1, which I expected. However, I want all the files and subdirectories of that directory to overwrite (and add to) the existing my-d8 directory.
I tried the mv command, but in my shell, it refused to overwrite existing non-empty subdirectories.
$ mv drupal-8.3.1/* my-d8/
mv: cannot move 'drupal-8.3.1/core' to 'my-d8/core': Directory not empty
mv: cannot move 'drupal-8.3.1/modules' to 'my-d8/modules': Directory not empty
...
Googling around, I found this AskUbuntu answer, but when I tried it, it didn't quite to the trick:
$ tar -xvf drupal-8.3.1.tar.gz --directory=my-d8 --strip-components=1
drupal-8.3.1/.csslintrc
drupal-8.3.1/.editorconfig
drupal-8.3.1/.eslintignore
... ^C
Instead of overwriting files in the repo's root, it simply put the subdirectory in the repo:
$ ls my-d8/drupal-8.3.1/
autoload.php composer.json composer.lock core/ README.txt
Edit I tried dope-ghoti's answer, and upon close examination, it didn't work:
$ ls
drupal-8.3.1.tar.gz my-D8/
$ tar -zx -f drupal-8.3.1.tar.gz -C my-D8
$ ls my-D8/drupal-8.3.1/
autoload.php composer.json ...
$ cd my-D8/
$ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
drupal-8.3.1/
nothing added to commit but untracked files present (use "git add" to track)
How can I easily extract the archive files and directories into their respective places in my repository?
$ tar --version
tar (GNU tar) 1.29
|
From the manual:
-C DIR
change to directory DIR
This alters the working directory of the tar process. You can also use --strip to remove the first component of the filenames (e. g. drupal-8.3.1/) in the archive. So, you can:
tar --strip=1 -zx -f drupal-8.3.1.tar.gz -C my-d8
If your tar doesn't have --strip, it should at least have --transform:
tar --transform 's_drupal-8.3.1/__' -zx -f drupal-8.3.1.tar.gz -C my-d8
| extract tar archive to existing directory in git-bash |
1,497,883,180,000 |
I'm wondering what the name of the default git mergetool on my linux server is?
|
The screenshot provided appears to be vimdiff.
| What is the name of the default git mergetool? |
1,497,883,180,000 |
I cloned a repo (using fictious examples here)
$ git clone http://someplace.somedomain.name/resource.git
went to the directory
$ cd resource
and then tried to edit a file within the resource directory
/home/shirish/resource $ editor somefile.txt
Now I am not familiar with what editor is being used by git and if it something internal. I am running git 2.11.0 on Debian testing.
I did hunt around and saw this https://help.github.com/articles/associating-text-editors-with-git/ but the documentation doesn't tell me how do I search to know/see which editor it uses. Is there a way ?
|
In Debian, the editor command is an alternative:
sudo update-alternatives --config editor
It's not managed by git.
When a git commands needs an editor (e.g. for a commit message), it uses the editor given by the GIT_EDITOR environment variable, or failing that, the editor specified by the core.editor variable. See git-var(1) and git-config(1) for details; but basically to set it up globally, run
git config --global core.editor emacs
which will store your preference in .gitconfig in your home directory.
| where is the 'Editor' variable kept in git? |
1,497,883,180,000 |
I have two branches, which contain a file that has recently been added to git ignore. It is an auto-generated file. I removed it in the master branch from the cache using git rm --cached fileName. However, i still get the message that he file would be overwritten when I try to change to the second branch using git checkout branchName. How can I get both branches to ignore the file, it seems like a catch to me - in order to change branch I would have to add the file again and commit it. I don't want to use git stash, since there are other changes I don't want to be persisted.
|
Commit your current changes and remove fileName.
| Git - Remove file from two branches |
1,497,883,180,000 |
I keep my dotfiles in a private git repo on bitbucket and this works great for the majority of my files (.vimrc, .tmux.conf etc) then I just set up symlinks from my home directory to my cloned gitrepo of dotfiles and everything works great.
My problem is that I also use the prezto framework to manage zsh plugins.
Prezto does something similar in that it stores all the .zprezto* config files in its own directory and symlinks to them from home.
One of those files is the .zshrc which it stores in its own directory.
It looks like this:
.zlogin -> /home/jordan/.zprezto/runcoms/zlogin
.zlogout -> /home/jordan/.zprezto/runcoms/zlogout
.zpreztorc -> /home/jordan/.zprezto/runcoms/zpreztorc
.zprofile -> /home/jordan/.zprezto/runcoms/zprofile
.zshenv -> /home/jordan/.zprezto/runcoms/zshenv
.zshrc -> /home/jordan/.zprezto/runcoms/zshrc
How am I able to track my .zshrc file in my own git dotfiles directory without breaking prezto.
|
You can use a hardlink in this instance, presuming you are not crossing file system boundaries. In case you are unaware, a hardlink is much like a symlink, but from a process perspective the file is a normal file. This includes git, which will properly work with them and archive them as normal files with content and not symlinks.
Because git doesn't track such links, however, if the file is deleted and recreated by the repo for some reason, it will break the hardlink, so that is something to keep an eye on when using git.
To be clear, I mean you create a hardlink from Pretzo's primary stored instance to a version in the directory where you keep the git backed dot files. Pretzo will see it as a regular file, so will git, and note hardlinked files can be symlinked, so their deployment that way is fine.
Like a symlink, it means a change to one version changes the other, since technically they are the same data on storage (with multiple associated file nodes). Beware hardlinks are harder to notice than symlinks with many tools since they are usually not explicitly indicated (I don't know how this applies to various GUI filebrowsers; I think generally they will just be regular files). However, you can spot them based on the number of links shown with ls -l (second column), stat, etc. Normal files that aren't hardlinked have a link count of 1 (and directories are not normal files, so their link count varies). Unfortunately, unlike with symlinks, there is no simple way to find the other nodes, just the link count indicating they exist. So do not start doing this willy-nilly, do it systematically as in this context so you know why and where the other nodes are.
Caveat
This does mean there is the potential, if you are deploying this way on multiple systems (your post is ambiguous on this point), to run into issues if Prezto is prone to making changes to these files of its own accord. That will lead to situations where a file has updates pending via a pull but these conflict with local changes made by Pretzo, and merging at that point is probably bad, so you would have to decide what to do (note you can delete a hardlink and it does not delete all the other copies).
However, if these are all configuration files that you know Pretzo only reads and does not screw with (which is sort of implicit in the idea of git tracking them across systems), then you are okay. Also, if you are just using this repo as a backup of one particular system it doesn't matter, the aforementioned scenario can't happen.
The only other issue is that you cannot use hardlinks across filesystem boundaries. I.e., if your master git backed store is on a mounted filesystem separate from Pretzo's own store, you are out of luck with this method.
| Git tracking dotfiles that are symlinked |
1,497,883,180,000 |
I want to download a portion of this diff: https://gist.github.com/sergeykish/650839#file-dvorak-de-diff. Pseudocode
git pull https://gist.github.com/sergeykish/650839#file-dvorak-de-diff.patch
|
git pull is used for updating existing repository. If you want to download the content of the new repository, there is git clone command:
$ git clone https://gist.github.com/sergeykish/650839
Cloning into '650839'...
remote: Counting objects: 15, done.
remote: Total 15 (delta 0), reused 0 (delta 0), pack-reused 15
Unpacking objects: 100% (15/15), done.
Checking connectivity... done.
$ cd 650839/
650839 (master)$ ls
dvorak-de.diff winkeys-ua.diff
650839 (master)$ cat dvorak-de.diff
You can download the single diff by clicking to the button Raw on the linked page. Or copy the url and from shell:
wget https://gist.githubusercontent.com/sergeykish/650839/raw/ce43a3b70e769b6de8ecf996298455bc0f622125/dvorak-de.diff
| Why you cannot `git pull SHA...650839#file-diff.pach`? |
1,497,883,180,000 |
Consider a Git log:
commit 4d6b30238fbfc972ea4505cadf43abd316506d9e
Author: Dotan Cohen <[email protected]>
Date: Mon Jan 11 22:41:21 2016 +0200
Final foobar version
commit 4d6b30238fbfc972ea4505cadf43abd316506d9e
Author: Dotan Cohen <[email protected]>
Date: Mon Jan 11 19:11:51 2016 +0200
Working foobars
commit 4d6b30238fbfc972ea4505cadf43abd316506d9e
Author: Dotan Cohen <[email protected]>
Date: Mon Jan 11 10:31:37 2016 +0200
Broken foobars
commit 4d6b30238fbfc972ea4505cadf43abd316506d9e
Author: Dotan Cohen <[email protected]>
Date: Mon Jan 10 21:47:22 2016 +0200
Added foobars
commit 4d6b30238fbfc972ea4505cadf43abd316506d9e
Author: Dotan Cohen <[email protected]>
Date: Mon Jan 10 11:54:12 2016 +0200
Preparation for foobars
How might I get the first and last time from each commit message for each day, then do a bit of math and estimate the total time spent? Something like this:
Date: Mon Jan 11 22:41:21 2016 +0200
Date: Mon Jan 11 10:31:37 2016 +0200
TOTAL A: 12:09:44
Date: Mon Jan 10 21:47:22 2016 +0200
Date: Mon Jan 10 11:54:12 2016 +0200
TOTAL B: 09:53:10
TOTAL: 22:02:54
For purposes of this issue, we can assume that all commits were done by the same person. Note that there can be an arbitrary amount of commits per day, and an arbitrary amount of days that may span different months or year boundaries.
|
The following Perl code should get you very, very close to what I think you want. If you're not familiar with Perl, you'll need to install the DateTime::Format::Strptime module from CPAN... cpan install DateTime::Format::Strptime.
Then, output your git log to a file git log > git.log.
After that, paste the following code into a file, put the log file in the same directory, and run it.
Not my prettiest or most efficient code, but I only had a few minutes to put something together.
#!/usr/bin/perl
use warnings;
use strict;
use DateTime::Format::Strptime;
my $log = 'git.log';
open my $fh, '<', $log or die $!;
my %dates;
my @order;
while (<$fh>){
if (/Date:\s+(.*?)(\d{2}:.*)/){
push @order, $1 if ! $dates{$1};
push @{ $dates{$1} }, "$1$2";
}
}
my $letter = 'A';
my $total_time = DateTime::Duration->new;
for my $day (@order){
my $start = $dates{$day}->[0];
my $end = $dates{$day}->[-1];
my $parser = DateTime::Format::Strptime->new(
pattern => '%a %b %d %H:%M:%S %Y %z',
on_error => 'croak',
);
my $dt1 = $parser->parse_datetime($start);
my $dt2 = $parser->parse_datetime($end);
my $total = $dt1 - $dt2;
$total_time = $total_time + $total;
print "$start\n$end\n";
print "Total $letter:\t";
print join ':', ($total->hours, $total->minutes, $total->seconds);
print "\n\n";
$letter++;
}
print "Total time overall: ";
print join ':', ($total_time->hours, $total_time->minutes, $total_time->seconds);
print "\n";
| Estimate time spent on Git project with grep |
1,497,883,180,000 |
I am running TCSH and I would like to update my prompt every time I run a command. I think can currently do that via backticks.
set tmpstr = `git status --untracked-files=no --porcelain`
set prompt="%{\e[35;1m%} $tmpstr %{\e[32;1m%}%n%{\e[37m%}@%{\e[33m%}%m%{\e[37m%}:%{\e[36m%}%~%{\e[37m%}"\$"%{\e[0m%} "
But I really don't want to have the full list of files every time. So just saying whether the GIT directory is clean is enough.
set tmpstr1 = `git status --untracked-files=no --porcelain`
if ("$tmpstr" == "") then
set gitstr = 'Git: Clean'
else
set gitstr = 'Git: Uncommitted GIT '
endif
set prompt="%{\e[35;1m%} \$gitstr %{\e[32;1m%}%n%{\e[37m%}@%{\e[33m%}%m%{\e[37m%}:%{\e[36m%}%~%{\e[37m%}"\$"%{\e[0m%} "
But the gitstr won't be updated, as it isn't a command. Any one got any other ideas? Or any magical ways of calling a full if statement each time I run a command?
|
I ended up using precmd
I put alias precmd 'source ~/.tcsh/precmd.tcsh' into my .cshrc file and moved my prompt set into that file.
Source of the .tcsh
set tmpstr = `(git status --untracked-files=no --porcelain >! ~/out ) >&! ~/out1`
#echo $tmpstr #for debugging
if !( -s ~/out ) then
if !( -s ~/out1 ) then
set gitstr = "Git: Clean"
set prompt="%{\e[35;1m%} \$gitstr %{\e[32;1m%}%n%{\e[37m%}@%{\e[33m%}%m%{\e[37m%}:%{\e[36m%}%~%{\e[37m%}"\$"%{\e[0m%} "
else
#echo "not in GIT"
set prompt="%{\e[35;1m%} %{\e[32;1m%}%n%{\e[37m%}@%{\e[33m%}%m%{\e[37m%}:%{\e[36m%}%~%{\e[37m%}"\$"%{\e[0m%} "
endif
else
set gitstr = "Git: Uncommitted GIT "
set prompt="%{\e[35;1m%} \$gitstr %{\e[32;1m%}%n%{\e[37m%}@%{\e[33m%}%m%{\e[37m%}:%{\e[36m%}%~%{\e[37m%}"\$"%{\e[0m%} "
endif
That allowed me to check when I am in get, and report the status back to the cmd line. When out of the GIT folder it just doesn't report GIT status. The shenanigans going on up in the tmpstr is to remove the stderror from the konsole.
| Updating a git variable in the Shell prompt on every command |
1,497,883,180,000 |
I've seen some tutorials on the internet in which people are using etckeeper to keep a log of their server configuration, and yet they use the git command directly instead of running it through the etckeeper vcs command.
This seems a little dangerous to me, since etckeeper is a proxy for the git command since etckeeper has to store file permissions and meta data in the .etckeeper directory. Is running git commands like this dangerous to the state of the .etckeeper directory or anything else related to it?
Does it depend on which command is run? Why or why not?
|
etckeeper vcs merely loads /etc/etckeeper/etckeeper.conf (which may, but usually doesn't set environment variables), determines which VCS system the repository uses, and calls the appropriate VCS command with the specified argument. If you know that the repository is stored under git, running etckeeper vcs foo or git foo makes no difference.
Running commands like etckeeper commit instead of git commit does make a difference, though not necessarily a critical one. To take the example of git commit, all the intelligence about permissions and ownership is in a hook. What etckeeper commit does (besides determining which VCS to use) is things like setting the author identity according to the etckeeper configuration, committing everything by default (so that etckeeper commit is like git commit -a), and passing extra flags set in the etckeeper configuration.
| Is it always necessary to run etckeeper git commands using the vcs command? |
1,497,883,180,000 |
I have installed java 8 on my bluehost VPS. I have followed http://tecadmin.net/install-java-8-on-centos-rhel-and-fedora/
instructions .
In order to add directories to PATH variable I have added
PATH=$PATH:/opt/jdk1.8.0_45/bin:/opt/jdk1.8.0_45/jre/bin
JAVA_HOME=/opt/jdk1.8.0_45
JRE_HOME=/opt/jdk1.8.0_45/jre
to etc/environment file.
After that I can't push upgrades to my git repository and when I login via ssh I can't run unix command.
My server OS is CentOS and its 64bit
EDIT :
Error shown in git :
git -c diff.mnemonicprefix=false -c core.quotepath=false push -v --tags origin master:master
Pushing to [email protected]:/home/darmanjo/darmanjoo.git
bash: git-receive-pack: command not found
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
SSH Problem :
login as: root
[email protected]'s password:
Last login: Tue Apr 21 15:26:53 2015 from 109-110-182-162-dynamic.shabdiznet.com
-bash: id: command not found
-bash: tty: command not found
[email protected] [~]# ls
-bash: ls: command not found
[email protected] [~]#
Also my echo $PATH shows :
/usr/local/sbin:/usr/sbin:/sbin:$PATH:/opt/jdk1.8.0_45/bin:/opt/jdk1.8.0_45/jre/bin:/root/bin
|
You can't use variable expansion in /etc/environment (which is why you see an unexpanded $PATH in the output from echo $PATH). /etc/environment is read by the pam_env module not a shell script so just simple assignments.
You probably want to add this stuff to /etc/profile or add a file under /etc/profile.d/.
See https://serverfault.com/questions/165342/can-you-use-variables-when-editing-etc-environment-in-ubuntu-10-04 for more details.
| Can't push git updates & run Unix commands when connecting via SSH |
1,497,883,180,000 |
I'm currently using RedHat Enterprise 6. Git had issues cloning Github repos using HTTPS. After some investigation (e.g. enabling GIT_CURL_VERBOSE and GIT_TRACE) the problem was narrowed to a certificate validation issue, which was solved updating the certificate DB, i.e.:
curl http://curl.haxx.se/ca/cacert.pem -o /etc/pki/tls/certs/ca-bundle.crt
Things worked fine for a while. However, after a system upgrade now I'm getting a different error:
Couldn't find host github.com in the .netrc file; using defaults
* About to connect() to github.com port 443 (#0)
* Trying 192.30.252.128... * Connected to github.com (192.30.252.128) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
* NSS error -5978
* Expire cleared
Unfortunately I can't find that error code description on the documentation.
It seems that the updated CURL system lib defaults to NSS and relies exclusively on the certificates on /etc/pki/nssdb
I've been trying to solve this issue trying different commands to add the certificates to NSS, but failed.
Can you recommend a solution? Is it possible to force Git and/or CURL to use the ca-bundle DB, or even disable certificate validation?
Any solution that could allow Git commands to be run using Github's repos wil be welcome.
Notes:
Curl version
curl 7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
|
I believe you can override the .crt file that git uses like this:
$ git config --system http.sslcainfo "/etc/pki/tls/certs/ca-bundle.crt"
You can disable SSL checks all together (not recommended):
$ git config --system http.sslverify false
| How can I add an x509 certificates bundle (ca-bundle.crt) to NSS database (~./pki/nssdb) |
1,497,883,180,000 |
I need a PHP script to perform git pull however I am not naive enough to give it permissions on git. I've wrapped git pull in a script which www-data has permissions for, but I'm not sure how to give the script permissions on git itself:
$ sudo tail -n1 /etc/sudoers
www-data ALL=(ALL) NOPASSWD: /home/php-scripts/git-pull
$ cat /home/php-scripts/git-pull
#!/bin/bash
/usr/bin/git pull
$ ls -la /home | grep php-scripts
drwxr-xr-x 2 ubuntu ubuntu 4096 Sep 3 09:26 php-scripts
$ ls -la /home/php-scripts/git-pull
-rwxrwxr-x 1 ubuntu ubuntu 30 Sep 3 08:44 /home/php-scripts/git-pull
$ cat /var/www/public_html/git-wrapper.php
<?php
$output = array();
$value = 0;
exec("/home/php-scripts/git-pull", $output, $value);
echo "<pre>";
echo "Return Value: {$value}\n";
foreach ( $output as $o) {
echo $o."\n";
}
?>
Note that /var/www/public_html/ is in fact a git repository. I often perform git pull in that directory from the CLI. However, when I call this script in a web browser I see that the files were not updated via git pull and the following is output to the browser:
Return Value: 1
This is on Ubuntu Server 12.04 with Git 1.7.9.5. The remote repository is on the same server.
|
Your script runs under www-data:www-data I suppose. You have to run the git pull with a user that have a write permission on your cloned repository. You have configured sudo, but you don't call it anywhere which doesn't make much sense (not saying you need to do that at all). Verify under what user you are running and then switch to appropriate one if needed and adjust permissions on your cloned repository accordingly.
| Allow www-data to perform specific commands |
1,497,883,180,000 |
My terminal has output like the one below.
pc@pop-os:~/my-project (main)$
This project was downloaded via GitHub. (main) is colored green. I set it as a branch name that appears on my terminal when I go to the project's directory. When I make a change, I want the terminal to recognize the change and change the (main) color to red. Does anyone who can help with that, please?
|
I used the parseGitBranch function to define the colors. Your function should look like this:
parseGitBranch () {
if ! git rev-parse --git-dir &> /dev/null; then
return
fi
branch="($(git branch --show-current))"
local STATUS
STATUS=$(git status --porcelain)
if [ -n "$STATUS" ]; then
echo -e "\033[38;5;1m $branch" #red
else
echo -e "\033[38;5;34m $branch" #green
fi
}
And you should set PS1 to:
PS1="\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\$(parseGitBranch) \[\033[00m\]\$\n>"
The code above could be inside ~/.bashrc.
Explanation
The following line will check if current directory is a git project:
if ! git rev-parse --git-dir &> /dev/null; then
return
fi
I've changed your code git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' to git branch --show-current. That's an easier way to get the current branch name.
Now, if the condition above is true then the function will check the status for the current git directory.
The most effective way to know if there are changes in your project is using git status --porcelain. So if you don't have any changes the output of git status --porcelain will be empty.
With -n "$STATUS" checks if the length of STATUS is nonzero.
If -n $STATUS is true then the branch color will be red (because you have changes): echo -e "\033[38;5;1m $branch" #red.
If it's false then the branch color will be green: echo -e "\033[38;5;34m $branch" #green.
You can check this link for more information about bash colors and formatting. Maybe your terminal doesn't support some formatting or the colors will not be printed correctly.
| How can I change terminal branch color? |
1,497,883,180,000 |
I had a git repo on machine A.
I did an rsync from machine A to machine B using the flags
rsync -zvaP /media/shihab/development shihab@remote:/media/shihab/OSDisk/development
Later I did some changes in machine B and did an rsync from machine B to machine A using the same flags:
rsync -zvaP shihab@remote:/media/shihab/OSDisk/development /media/shihab/development
During the sync, I realized that even the files without modifications were synced. Turns out both times of the sync operation, the file owner and permissions were changed. Doing a git status in the repo would tell me that user permissions were changed.
To rectify this, I made changes to the git config global and local by adding core.filemode=false as:
git config --global core.fileMode false
git config --local core.fileMode false
Furthermore, I added the flags, rsync -zvaP --no-perms --no-owner --no-group to my sync to ask rsync to forget about writing the permissions. For example:
rsync -zvaP --no-perms --no-owner --no-group /media/shihab/development shihab@remote:/media/shihab/OSDisk/development
However, despite that change, when I rsync from machine B to machine A, it is overwriting a file with a newer timestamp with that on machine B with an older time-stamp. I can see it if I do a --dry-run -i. The file looks like this on machine B:
-rwxrwxrwx 1 shihab shihab 655 Nov 16 2021 install-i3wm.sh*
While on machine A it looks like:
-rwxrwxrwx 1 shihab shihab 681 Jun 22 11:06 install-i3wm.sh*
when I do an rsync from Machine B to machine A as follows:
rsync -zvaP --dry-run -i -t --no-perms --no-owner --no-group shihab@remote:/media/shihab/OSDisk/development /media/shihab/development
I get:
f+++++++++ install-i3wm.sh
What am I doing wrong?
|
You say that rsync "is overwriting a file with a newer timestamp with that on machine B with an older time-stamp".
The two files are different so the destination will be updated to match the source. That's what rsync does.
If you want rsync only to update files when the source is newer than the destination you needed to tell it that's the modified behaviour that you want. In this case include -u (--update).
| Rsync not considering timestamps while syncronising git repos after permissions changed |
1,497,883,180,000 |
I have a git hook (post-receive) to update the documentation, run the unit-tests etc. etc., but the thing is sometimes not working.
Here are the contents of the post-receive hook:
#!/usr/bin/bash
~/bubblegum_ci > /tmp/bubblegum_ci_log 2>&1 &
That's not hard to understand, just launch a script in the background and pipe stdout and stderr to a logfile.
Here are the contents of bubblegum_ci:
#!/usr/bin/bash
id
cd /home/git/bubblegum
pwd
GIT_CURL_VERBOSE=1 GIT_TRACE=1 git pull -v .
make genhtml doxygen
This one is also very simple; just cd to another repository, pull any changes, and invoke make to take care of the actual work. Sometimes it works just fine. Sometimes, the script gives the following output:
uid=1001(git) gid=1001(git) groups=1001(git),1002(www)
/home/git/bubblegum
fatal: not a git repository: '.'
make genhtml doxygen
<the output from make showing that the commits I just pushed have not been pulled>
That first line, /home/git/bubblegum obviously is the output from pwd, but then git fails to pull, saying it's not a git repo. I'm confused by the fact that this sometimes works and sometimes doesn't. Can anyone here shed any light on the issue? Is there a race condition I haven't spotted? Otherwise I would be interested to see if there's a better way to handle this kind of thing.
Here are the permissions for /home/git/bubblegum/.git:
git@fancy-server:~$ ls /home/git/bubblegum -al | grep \\.git
drwxr-xr-x 8 git git 4096 Sep 2 09:58 .git
here is the output of ls -l /home/git/bubblegum/.git/:
$ ls -l .git
total 52
-rw-r--r-- 1 git git 84 Sep 2 09:58 FETCH_HEAD
-rw-r--r-- 1 git git 23 Aug 31 15:42 HEAD
-rw-r--r-- 1 git git 41 Sep 2 09:58 ORIG_HEAD
drwxr-xr-x 2 git git 4096 Aug 31 15:42 branches
-rw-r--r-- 1 git git 251 Aug 31 15:42 config
-rw-r--r-- 1 git git 73 Aug 31 15:42 description
drwxr-xr-x 2 git git 4096 Aug 31 15:42 hooks
-rw-r--r-- 1 git git 1875 Sep 2 09:52 index
drwxr-xr-x 2 git git 4096 Aug 31 15:42 info
drwxr-xr-x 3 git git 4096 Aug 31 15:42 logs
drwxr-xr-x 151 git git 4096 Sep 2 09:52 objects
-rw-r--r-- 1 git git 114 Aug 31 15:42 packed-refs
drwxr-xr-x 5 git git 4096 Aug 31 15:42 refs
Here si the output of mount | grep home:
/dev/sda6 on /home type ext4 (rw,relatime)
|
The problem was to do with environment variables. The clue here was the fact it worked on the command line and not in whatever environment gets spun up by whatever runs the git hook.
So I put the env command in the script, and noticed GIT_DIR=".". This explains the cryptic error message fatal: not a git repository: '.'. Sure enough, setting GIT_DIR is a thing and there is a command line option to override the environment variable.
Thanks also to Raphael Ahrens who in the comments pointed out the incorrect period at the end of the command git pull .. The command to do the pull now looks like git --git-dir="/home/git/bubblegum/.git/" pull -v and this seems to be doing okay.
| Why is this path only sometimes not a git repository? |
1,497,883,180,000 |
I have a zsh alias:
gitbs() {
git branch | grep -- $1
}
And I would like to pass the result into git checkout, for example:
git checkout | gitbs state
How can I make this work?
|
A shell pipe passes the output of a command to the input of another command. This won't help you here: you want to pass the output of a command as a command line argument of another command. The tool for that is command substitution. So the basic idea is
git checkout "$(gitbs state)"
(It's still a pipe under the hood, but the reader side of the pipe is the shell itself: it reads the output and then constructs a command line including that output.)
However, the output of gitbs state is not the right format to pass to git checkout: it has extra spaces and sometimes punctuation characters on the same line as the branch name. (Also color formatting codes, but only when the output is a terminal or when git calls a pager automatically, not when the output is a pipe.) Also, if there is no matching branch or more than one, you'll get a somewhat weird error message from git checkout.
To fix this, you can change gitbs to produce the raw branch name(s) as output. Here's a version that keeps the pretty formatting intended for humans if the output is a terminal, and just prints one branch name per line otherwise. It uses git for-each-ref to enumerate branch names. The conditional expression -t 1 tests whether standard output is a terminal.
gitbs () {
if [[ -t 1 ]]; then
git branch
else
git for-each-ref --format='%(refname:lstrip=2)' 'refs/heads/*'
fi | grep -- "$1"
}
With this definition of gitbs, git checkout "$(gitbs state)" will work.
Note the double quotes around the command substitution. Without double quotes (git checkout $(gitbs state)), the output is split into separate arguments at whitespace, so if multiple branches match, the resulting command will be something like git checkout foobar1 foobar2, which will not check out foobar1 but instead will overwrite the current version of the file foobar2 with the version from foobar1 if a file named foobar2 exists.
To avoid this pitfall, it may be better to define a different version of gitbs which requires a single matching branch. You get the benefit of a clearer error message if there are zero or more than one matching branches, although there's still an extra message about the current branch from git checkout. This function puts the list of matching branches in an array
gitbs1 () {
local branches
branches=($(git for-each-ref --format='%(refname:lstrip=2)' 'refs/heads/*' | grep "$1"))
if ((#branches == 0)); then
echo "No branch contains '$1'" >&2
return 3
fi
if ((#branches > 1)); then
echo "Multiple branches match '$1':" >&2
print -lr $branches >&2
return 3
fi
echo $branches
}
Then you can safely write git checkout $(gitbs1 state).
If you turn on the option glob_complete (i.e. setopt glob_complete in your .zshrc), then you can type
git branch *foo*Tab
and *foo* will be replaced by the name of the matching branch if there is one. If there are multiple matching branches, you'll get the same kind of menu or cycling behavior as for ordinary (prefix) completion.
| How to pass zsh alias function to pipe |
1,497,883,180,000 |
I am trying to execute a script that pushes to git every x minutes as a service, but git uses 100% CPU and high amounts of RAM while seemingly doing nothing. (I checked after 8 minutes and it was still going)
When I execute the script manually it works perfectly and takes only a few seconds.
backupToGit.sh:
#!/bin/bash
cd /home/pi/<Projectfolder>
cat /root/.ssh/id_rsa.pub
while true
do
git add *
git commit -m "auto backup"
echo "------------Starting to push to Github------------"
git push [email protected]:JustLokust/<Projectname> master
echo "------------Finished pushing to Github------------"
sleep 300
done
Service:
[Unit]
Description=<Service Name>
[Service]
WorkingDirectory=/home/pi/<Projectfolder>
ExecStart=/home/pi/<Projectfolder>/backupToGit.sh
[Install]
WantedBy=multi-user.target
|
I think I just found the Solution myself with the Help of @OlivierDulac :
The Service was only setup to start the script which would run in an endless loop, but never to stop the script. this probably resulted in the script running one more time for every time I started / restarted the Service leading to an overlap in git instances and high Resource usage.
This ultimately blocked the execution of the script.
What you need to do to Reproduce the fix: Restart your server or kill all the Remaining Processes that run the looping script.
| I am trying to execute a script that pushes to git every x minutes as a service, but git uses 100% CPU and high amounts of RAM |
1,497,883,180,000 |
A little background- I recently upgraded my headless Ubuntu Server 18.04 install to 20.04. In that process, webmin somehow was gone from my system. The repository was disabled. So I re-enabled, then re-installed. Most everything was where I wanted it to be (SMB server config) and basically only my menu customizations and custom commands were gone.
Now, on webmin, it will not show running processes. It say's 0. That is the only thing I've noticed that is broken. So I posted on webmin's github page, and got a prompt response that the issue was fixed here. So I guess my question is more of a git question than a webmin question, because I really am not sure how to implement the fix on that page to my webmin install. If anyone can steer me in the right direction I'd be appreciative of that.
|
That helped me out! I couldn't figure out how to download that as a patch, but the file it is referencing on my system was under /usr/share/webmin/proc/. There I backed up linux.lib.pl then edited it in nano. There I changed the lines noted in the patch (+ for add, - for take away), saved, and it worked. Otherwise if I could download it I would have just used the patch command.
| Webmin not showing running processes after upgrade to Ubuntu Server 20.04 from 18.04 |
1,497,883,180,000 |
Brief:
I would like to restrict port-forwarding from an SSH user identified by password.
Explanation:
In the following explanation of how to install a git server:
https://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server
They explain that an SSH user with limited or no shell access could still use port-forwarding and some other OS services.
At this point, users are still able to use SSH port forwarding to
access any host the git server is able to reach.
In this same text, they solve the problem by restricting SSH access in ~/.ssh/authorized_keys using no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty.
I would like to do the same using password identification: I know that asymmetric cryptographic keys are usually more secure than password, but it also prevent accessing a server from "anywhere" without having your private key in the pocket.
It seems (to me) that authorized_keys only applies to ssl key identification and not to password.
How to limit port forwarding when using password identification?
Note: Using CentOS 8
|
you can do the same in sshd.config but you need to disable shell access, because they still can run their own sshd see this question
AllowTcpForwarding no
AllowStreamLocalForwarding no
GatewayPorts no
PermitTunnel no
| How to forbid port-forwarding for a password protected SSH user? |
1,497,883,180,000 |
When I use git or curl I get an error which may be related to certificates:
With git:
> git clone https://github.com/vim/vim.git
Cloning into 'vim'...
fatal: unable to access 'https://github.com/vim/vim.git/': error:140943E8:SSL routines:ssl3_read_bytes:reason(1000)
With curl
> curl -v https://github.com
* Trying 2001:8002:e42:f002::f5ff:443...
* TCP_NODELAY set
* Connected to github.com (2001:8002:e42:f002::f5ff) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/pki/tls/certs/ca-bundle.crt
CApath: none
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS alert, close notify (512):
* error:140943E8:SSL routines:ssl3_read_bytes:reason(1000)
* Closing connection 0
curl: (35) error:140943E8:SSL routines:ssl3_read_bytes:reason(1000)
If I try to see what is going on with openssl it doesn't seem to find any certificates:
> openssl s_client -ciphersuites TLS_AES_128_GCM_SHA256 -connect github.com:443
CONNECTED(00000003)
139703172380480:error:140943E8:SSL routines:ssl3_read_bytes:reason(1000):ssl/record/rec_layer_s3.c:1543:SSL alert number 0
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 7 bytes and written 316 bytes
Verification: OK
---
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
Early data was not sent
Verify return code: 0 (ok)
---
When I run the openssl command (above) on another machine it returns lots of info about certificates.
What can I do to diagnose/fix this problem?
I am using Fedora 31
Edit: Part of the output from "nmcli con show " is:
ipv6.method: auto
ipv6.dns: --
ipv6.dns-search: --
ipv6.dns-options: --
ipv6.dns-priority: 0
ipv6.addresses: --
ipv6.gateway: --
ipv6.routes: --
ipv6.route-metric: -1
ipv6.route-table: 0 (unspec)
ipv6.routing-rules: --
ipv6.ignore-auto-routes: no
ipv6.ignore-auto-dns: no
ipv6.never-default: no
ipv6.may-fail: yes
ipv6.ip6-privacy: -1 (unknown)
ipv6.addr-gen-mode: stable-privacy
ipv6.dhcp-duid: --
ipv6.dhcp-send-hostname: yes
ipv6.dhcp-hostname: --
ipv6.token: --
|
You apparently have an improperly set up IPv6 configuration. As a workaround (not a fix but that may be complicated or impossible), please disable IPv6 completely on the computer and try the git command again.
Disable IPv6 by typing (as root):
echo 0 > /proc/sys/net/ipv6/conf/all/autoconf
echo 0 > /proc/sys/net/ipv6/conf/all/accept_ra
echo 1 > /proc/sys/net/ipv6/conf/all/disable_ipv6
This will be effective until the next reboot. In order to permanently disable IPv6 on your computer (until you undo it of course) you need to change configuration files. How this is done is sadly very much dependent on your system. Under Fedora this can probably done by editing the configuration file for your network which is located in /etc/sysconfig/network-scripts and carries the name of your ethernet network, perhaps something like ifcfg-enp4s2 if your network (see ip a) is called enp4s2. Please add (or edit if it exists and is =yes) the line
IPV6INIT=no
This will be effective from the next restart of your network services (or reboot).
A different method that may or may not work on your system is to find the file /etc/sysctl.conf and add these lines (or adapt them if they exist):
net.ipv6.conf.all.autoconf = 0
net.ipv6.conf.all.accept_ra = 0
net.ipv6.conf.all.disable_ipv6 = 1
and let us know.
Full disclosure: Lines to disable IPv6 copied from How can I disable IPv6 in custom built embedded setup .
| openssl is not finding any certificates |
1,497,883,180,000 |
I not familiar with shell script for due replace the git clone to another command,
Below is the script:
git clone https://github.com/yyuu/pyenv.git ~/.pyenv
git clone https://github.com/yyuu/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv
Above two link folder already downloaded:
i'm totally genius try to unzip the download folder of course this two way is not the same.
unzip pyenv-master.zip to ~/.pyenv
unzip pyenv-virtualenv-master.zip to ~/.pyenv
Could anyone give me a hand for this, thank you.
|
just use another directory name in the git clone command, e.g.
git clone https://github.com/yyuu/pyenv.git ~/.pyenv2
git clone https://github.com/yyuu/pyenv-virtualenv.git ~/.pyenv2/plugins/pyenv-virtualenv
or download the packages manually:
Go to https://github.com/yyuu/pyenv and https://github.com/yyuu/pyenv-virtualenv, expand green Clone or download button on the right and hit Download ZIP.
Extract the files manually and copy over to .pyenv.
EDIT
If you need to use git clone, you can make a condition, to do clone only if the directory doesn't exist:
if [ ! -d "/full/path/to/.pyenv" ]
git clone https://github.com/yyuu/pyenv.git /full/path/to/.pyenv
git clone https://github.com/yyuu/pyenv-virtualenv.git /full/path/to/.pyenv/plugins/pyenv-virtualenv
else
do something else
fi
| How to change git clone to other way if the folder is already downloaded manually by Shell Script? |
1,497,883,180,000 |
So, I have a file, for this instance we shall call it $HOME/Documents/hello.txt. I will write some text inside it:
Hello, welcome to my text file
And I will hard-link this file here: $HOME/Documents/Backup/hello.txt.
Okay, great, this is now hard-linked. If I write to the original file, the hard-link will be updated:
echo "Hello again" >> $HOME/Documents/hello.txt
cat $HOME/Documents/hello.txt
Hello, welcome to my text file
Hello again
cat $HOME/Documents/Backup/hello.txt
Hello, welcome to my text file
Hello again
Now, my problem is, whenever I open either file (either of the hard-linked counterparts) with lots of programs that create temporary files, it loses its link relationship, and neither file will update the other anymore.
So, what can I do in this situation?
Note: I can not use symlinks in this situation, because I am using my hard link for Github to backup some files, and Git doesn't follow symlinks.
|
As mosvy already said in this comment, most editors do the edits in a copy of the original file which they replace (delete) later. While this increases security, it breaks hard links.
However, some editors like for example GNU Emacs can be configured to perform file edits in place, which means that they directly alter the original file, like you did in the shell. For example this Question and the corresponding answer discuss exactly your problem with respect to Gnu Emacs. So your editor's configuration would be the first point to look at.
Since you need the hard link only (?) for Git—unfortunately you are not very detailed on your workflow—, it is likely that you can use Git hooks to reestablish a correct hard link immediately before committing what you subsequently like to push to GitHub: The pre-commit hook seems to be a promising candidate for that. See man page githooks(5) for details.
| What to do when hard link is lost because of my text editor |
1,497,883,180,000 |
Was creating a script to update a Github application in-place and needed to print changes made in the latest Git tagged release so users could make an informed decision about pulling the trigger on the update before altering a working production environment. A requirement was that I needed to alias the last tag because I wanted to automate as much as possible without having to change the tag that prints every release.
|
Since your own solution appears to require that the checked out head match the tag you’re interested in, the following works without a separate git describe:
git tag -l -n10 --points-at HEAD
| How to show latest release's Git tag with message |
1,497,883,180,000 |
I am trying to clone Wayland repository from git (for a project) but git clone command is throwing me an error.
I installed curl (from here). After cloning make && make install. Earlier I had a different version which was working fine with git.
Then I again tried cloning Wayland repository and this error popped.
fatal: unable to access 'https://github.com/nobled/wayland.git/': Protocol "https" not supported or disabled in libcurl
so tried building curl as ./configure --with-ssl=/usr/local/ssl but I am not able to make any visible changes in curl's behaviour
/usr/local/ssl is a bad --with-ssl prefix!
I also tried this with /etc/ssl/ but failed
/etc/ssl is a bad --with-ssl prefix!
Any suggestion what may have caused this?
|
The switch
--with-ssl={gnutls,openssl}
needs the location of the the header files (*.h) usually in /usr/include/openssl it's a good idea to run configure with --includedir=/usr/include/ telling configure where to look for includes.
If /usr/include/openssl exists on your system and is having *.h files - it should be the right place.
You need to install the
openssl-devel (cent / redhat with yum) or libssl-dev (debian, ubuntu with apt) package otherwise. (Or clone the files from github.com 1.1.1 stable branch).
--with-ssl=/usr/include/openssl
EDIT:
ls /usr/include/openssl
aes.h buffer.h cterr.h engineerr.h md5.h pem.h rsa.h symhacks.h
asn1err.h camellia.h ct.h engine.h mdc2.h pkcs12err.h safestack.h tls1.h
asn1.h cast.h des.h e_os2.h modes.h pkcs12.h seed.h tserr.h
asn1_mac.h cmac.h dherr.h err.h objectserr.h pkcs7err.h sha.h ts.h
asn1t.h cmserr.h dh.h evperr.h objects.h pkcs7.h srp.h txt_db.h
asyncerr.h cms.h dsaerr.h evp.h obj_mac.h rand_drbg.h srtp.h uierr.h
async.h comperr.h dsa.h hmac.h ocsperr.h randerr.h ssl2.h ui.h
bioerr.h comp.h dtls1.h idea.h ocsp.h rand.h ssl3.h whrlpool.h
bio.h conf_api.h ebcdic.h kdferr.h opensslconf.h rc2.h sslerr.h x509err.h
blowfish.h conferr.h ecdh.h kdf.h opensslv.h rc4.h ssl.h x509.h
bnerr.h conf.h ecdsa.h lhash.h ossl_typ.h rc5.h stack.h x509v3err.h
bn.h cryptoerr.h ecerr.h md2.h pem2.h ripemd.h storeerr.h x509v3.h
buffererr.h crypto.h ec.h md4.h pemerr.h rsaerr.h store.h x509_vfy.h
EDIT2:
Make sure it's openssl v1.0.2. Compiling curl doesn't seem to work with openssl v1.1.1a
| Protocol SSL is not working with Curl |
1,548,613,238,000 |
I was just following the install instructions for zsh-autosuggestions and I don't understand what part of the following command is doing:
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
What does the ${ZSH_CUSTOM:- ...} do?
Why not just clone directly into ~/.oh-my-zsh/...?
|
The parameter substitution ${variable:-value} would be replaced by $variable if that variable was set and not empty, otherwise it's replaced by value. This is a standard parameter expansion.
In this case, it allows the user to set ZSH_CUSTOM to where they keep their oh-my-zsh customisation files, or to not set it and use the default location of ~/.oh-my-zsh/custom.
Not using this construct would make the life of users who have tailor made setups a bit awkward as they would have to either manually modify the command, or move the files to the correct place after installation (and possibly run the risk of having pre-existing files overwritten by git clone).
| Understanding environment variable / shell syntax |
1,548,613,238,000 |
I have this in a script:
set -e;
base="remotes/origin/dev";
git checkout --no-track -b "$new_branch";
git rebase "$base";
on occasion, there are conflicts of course, and what happens is that git rebase exits with 1, and so the script aborts/exits early.
So my automated script doesn't work if there are conflicts, which is frequent enough that it defeats the purpose.
My question is, is there some way to suspend the script upon a non-zero exit code, and then resume the script upon a signal or something? Something like this:
git rebase "$base" || suspend --until x;
so in some other terminal I can resolve stuff and then when I am done in the current terminal I could resume? Something like that?
|
To run the command once, but pause for failure:
if ! git rebase "$base"; then
read -p "Press ENTER when you think you've fixed it"
fi
| Allow automated script to incorporate git rebase |
1,548,613,238,000 |
I have 2 different branches A,B that have a (slightly different) version of a file X.
I am interested in getting the commits that added some specific patterns in branch B.
What I do roughly: diff files| grep "^\+" | grep "$PATTERN" | for loop grep -n.. do git blame -L done
This works but I was wondering if I am re-inventing/going a roundabout for something that is readily supported in git.
Is there a better way?
|
I think you can combine git blame and git merge-base to get the information you’re after:
git blame -n $(git merge-base A B).. -- file | grep -v "^^" | grep "$PATTERN"
This finds the common ancestor between A and B, then runs git blame on file, ignoring anything older than the common ancestor (the .. notation tells git blame to look at revisions starting with the ancestor and ending at the current head). -n adds line numbers in the output. Then grep -v "^^" removes any lines which haven’t changed since the common ancestor, and finally grep "$PATTERN" looks for the pattern among only the lines which have changed. Since git blame in non-reverse mode only shows the lines currently in the file, the results will only include added or modified lines, which is exactly equivalent to your ^\+ filter.
| Getting differences of file between specific revisions/branches |
1,548,613,238,000 |
I use GitLab repositories with two users (myself and a test user). For my test repository I have this in .git/config:
[core]
sshCommand = ssh -i /test-project/test_id_rsa
[remote "origin"]
url = [email protected]:test.tester/test-repo.git
And I don't use a passphrase at all with test_id_rsa.
'git pull', etc. works fine, but only when keychain is not running.
When keychain is running, it seems my usual SSH key gets used, and Git commands will not work, as I come across as wrong key pair is used.
Without keychain:
lynoure@laptop:~/repo$ ssh -i ~/.ssh/a_test.tester_key [email protected]
Welcome to GitLab, test tester!
Connection to gitlab.example.com closed.
I start keychain with the shell, by:
eval `keychain --eval --agents ssh id_rsa
When I have started keychain:
lynoure@laptop:~/repo$ ssh -i ~/.ssh/a_test.tester_key [email protected]
Welcome to GitLab, Lynoure!
Connection to gitlab.example.com closed.
Is there some way I can avoid needing to disable keychain every time I use my test-repo in the tests?
|
If this is a key that one reasonably often, the trick is to add that key to keychain:
eval `keychain --eval --agents ssh id_rsa a_test.tester_key
After that, the right key will get used.
If one uses a key less often, or uses a lot of different keys, best just to stop keychain for that.
| Keychain ssh-agent overriding specified SSH key |
1,548,613,238,000 |
I'm trying to set up an ssh connection from an OS X box provided by Travis CI to git-over-ssh at github.com.
Nothing fancy: my script takes a base64-encoded passwordless private key, decodes it and setups up the following git ssh wrapper to enforce key usage:
unset SSH_AGENT_PID SSH_AUTH_SOCK
# Setting up bot key
echo "$BOT_SSH_KEY" | base64 --decode >$HOME/bot_id
chmod 600 $HOME/bot_id
# Setting up ssh wrapper
cat >$HOME/git-ssh <<__EOF__
#!/bin/sh -efx
ssh -vv -i "$HOME/bot_id" "\$@"
__EOF__
chmod a+x $HOME/git-ssh
export GIT_SSH="$HOME/git-ssh"
Then it tries to do ssh-authenticated git clone, which, according to the logs, results in ssh client being called. The very same script works on Ubuntu Linux instances provided by Travis and fails on OS X instances:
Success log at Linux
Failure log at OS X
Analyzing the logs, they both look very similar, expect for:
Ubuntu uses OpenSSH_6.6.1, OS X uses OpenSSH_6.9p1 => kex_parse_kexinit lists slightly different set of ciphers available
Ubuntu uses /home/travis/bot_id, OS X uses /Users/travis/bot_id
OS X issues extra warnings for not being able to see the public part of the key (probably not a big deal):
debug1: key_load_public: No such file or directory
Ubuntu suceeds after:
debug1: Server host key: RSA 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /home/travis/.ssh/known_hosts:2
Warning: Permanently added the RSA host key for IP address '192.30.253.112' to the list of known hosts.
debug1: ssh_rsa_verify: signature correct
debug2: kex_derive_keys
debug2: set_newkeys: mode 1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug2: set_newkeys: mode 0
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: /home/travis/bot_id ((nil)), explicit
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /home/travis/bot_id
debug1: key_parse_private2: missing begin marker
debug1: read PEM private key done: type RSA
debug2: we sent a publickey packet, wait for reply
debug1: Authentication succeeded (publickey).
Authenticated to github.com ([192.30.253.112]:22).
...
OS X fails with:
debug1: Server host key: ssh-rsa SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8
debug1: read_passphrase: can't open /dev/tty: Device not configured
debug1: permanently_drop_suid: 501
ssh_askpass: exec(/usr/X11R6/bin/ssh-askpass): No such file or directory
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
As far as I understand, ssh client should at the very least (1) connect, (2) verify server's keys and identity, (3) start trying various auth methods. From what I see, OS X gets the connection, but then does not even try to do any verifications (or complain about RSA checks failed, or whatever), but somehow bypasses all pre-set auth methods (i.e. passwordless key) and directly proceeds to "ask authentication information interactively" method => and then fails, as it's obviously disabled, as CI is not an interactive server.
Any ideas what's wrong with OS X ssh and how to get it to work, or at least add some debug? As my guesses go, probably it somehow silently fails on server's identity check, but I have no idea how to debug that (especially given that I don't have any OS X boxes handy to try it interactively).
|
It turned out that indeed the problem was in the contents of .ssh/known_hosts file. Travis's ssh uses pretty much default options, so it would try to ask for confirmation on every new key, which, in turn, will result in this obscure error message.
On Ubuntu, Travis team supplies a preset .ssh/known_hosts file, which contains 5 lines with popular github keys:
github.com,192.30.252.129 ssh-dss AAAAB3NzaC1kc3MAAACBANGFW2P9xlGU3zWrymJgI/lKo//ZW2WfVtmbsUZJ5uyKArtlQOT2+WRhcg4979aFxgKdcsqAYW3/LS1T2km3jYW/vr4Uzn+dXWODVk5VlUiZ1HFOHf6s6ITcZvjvdbp6ZbpM+DuJT7Bw+h5Fx8Qt8I16oCZYmAPJRtu46o9C2zk1AAAAFQC4gdFGcSbp5Gr0Wd5Ay/jtcldMewAAAIATTgn4sY4Nem/FQE+XJlyUQptPWMem5fwOcWtSXiTKaaN0lkk2p2snz+EJvAGXGq9dTSWHyLJSM2W6ZdQDqWJ1k+cL8CARAqL+UMwF84CR0m3hj+wtVGD/J4G5kW2DBAf4/bqzP4469lT+dF2FRQ2L9JKXrCWcnhMtJUvua8dvnwAAAIB6C4nQfAA7x8oLta6tT+oCk2WQcydNsyugE8vLrHlogoWEicla6cWPk7oXSspbzUcfkjN3Qa6e74PhRkc7JdSdAlFzU3m7LMkXo1MHgkqNX8glxWNVqBSc0YRdbFdTkL0C6gtpklilhvuHQCdbgB3LBAikcRkDp+FCVkUgPC/7Rw==
github.com,192.30.252.129 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==
gist.github.com,192.30.252.141 ssh-dss AAAAB3NzaC1kc3MAAACBANGFW2P9xlGU3zWrymJgI/lKo//ZW2WfVtmbsUZJ5uyKArtlQOT2+WRhcg4979aFxgKdcsqAYW3/LS1T2km3jYW/vr4Uzn+dXWODVk5VlUiZ1HFOHf6s6ITcZvjvdbp6ZbpM+DuJT7Bw+h5Fx8Qt8I16oCZYmAPJRtu46o9C2zk1AAAAFQC4gdFGcSbp5Gr0Wd5Ay/jtcldMewAAAIATTgn4sY4Nem/FQE+XJlyUQptPWMem5fwOcWtSXiTKaaN0lkk2p2snz+EJvAGXGq9dTSWHyLJSM2W6ZdQDqWJ1k+cL8CARAqL+UMwF84CR0m3hj+wtVGD/J4G5kW2DBAf4/bqzP4469lT+dF2FRQ2L9JKXrCWcnhMtJUvua8dvnwAAAIB6C4nQfAA7x8oLta6tT+oCk2WQcydNsyugE8vLrHlogoWEicla6cWPk7oXSspbzUcfkjN3Qa6e74PhRkc7JdSdAlFzU3m7LMkXo1MHgkqNX8glxWNVqBSc0YRdbFdTkL0C6gtpklilhvuHQCdbgB3LBAikcRkDp+FCVkUgPC/7Rw==
gist.github.com,192.30.252.141 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==
ssh.github.com,192.30.252.149 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==
However, on OS X, this file doesn't exist, which triggers an error. This simplest solution is to just precreate the file with lines like this on OS X from a shell script.
I've raise an issue with Travis team for this one.
| ssh connection from OS X client problem |
1,548,613,238,000 |
I use my ikiwiki for personal notes only on my laptop locally (the html pages are under ~/public_html/mywiki) and now I am trying to edit it with emacs and push from command line.
I have some questions about this:
Is the following workflow correct:
cd ~/mywiki
edit and save ~/mypage.mdwm with emacs
git add ~/mypage.mdwm
git commit -m "mypage edit"
git push
Since I also sometimes want to edit it from the web interface, I tested it and noticed that it doesn't seem that I have to pull before editing. If I save an edit from the web interface the directory ~/mywiki is updated magically without using git pull.
Is this correct so far or is there a better workflow?
After editing and saving the page from the web interface it is saved with root permissions in ~/mywiki how can I make ikiwiki to save everything with my username as group and owner?
|
ad question 1:
This seems to be correct. If you set git_wrapper to git_wrapper: /home/user/mywiki/.git/hooks/post-commit (instead of git_wrapper: /home/user/mywiki.git/hooks/post-update you don't need the push step.
You may also think about another working clone of your wiki. But as long as you have a single user setup and you don't edit via web interface and editor at the same time, it should be fine to work inside scrdir as you described. See also this question: Why do I need 3 git repositories for ikiwiki if I want to commit locally)
ad question 2:
I am not quite sure where the problem comes from, maybe that you did run ikiwiki with sudo during setup. I suggest the following to fix it:
Make sure, that public_html is owned by you (sudo chmod myuser:myuser ~/public_html)
Resetup the wiki via cloning:
Clone the bare repository: git clone --bare ~/mywiki.git ~/newiki.git (even if the files in mywiki.git are owned by root the files in ~/newiki.git will owened by myuser)
cp ~/mywiki.git/config ~/newiki.git/config
Make new srcdir: git clone ~/newiki.git ~/newiki (~/newiki will be your new srcdir)
Make new config file: cp ~/mywiki.setup ~/newiki.setup and rename all occurences of mywiki with newiki.
Then run (without sudo): ikiwiki --setup newiki.setup --getctime
Test in your browser: 127.0.0.1/~myuser/newiki
If everything works you may (after an backup) delete mywiki and rename newiki to mywiki if you want.
| Using ikiwiki via command line: Workflow and permission problem |
1,548,613,238,000 |
We are in the process of moving from other source/version control methods to git and, because I have no actual experience with git (short of setting some user.* variables), I'd like to ask whether this is a viable direction to take before committing myself down this road.
The solution in "Is it possible to set the users .gitconfig (for git config --global) dynamically?" came close for me but it did not address a situation I discovered using shared service accounts (and which may exist for root, too).
I found that User1 would connect and /home/serviceaccount/.gitconfig would get set, then User2 would connect and overwrite that: an execution of git config --global user.name in either session would return User2 details, suggesting the file is referenced at each call. Because I don't do root, I don't know if this problem exists for two users who sudo to root following @oXiVanisher's solution.
To make this dynamic for shared service accounts, a wrapper script rolls in the appropriate .gitconfig based on the user executing it. The core of it is:
#!/bin/sh
myuser=`who -m | awk '{ print $1 }'`
HOST=`hostname`
# atomic locking over NFS via https://unix.stackexchange.com/a/22062
LOCKFILE="/local/share/bin/.git.lock"
TMPFILE=${LOCKFILE}.$$
echo "$myuser @ $HOST" > $TMPFILE
if ln $TMPFILE $LOCKFILE 2>&-; then
:
else
echo "$LOCKFILE detected"
echo "Script in use by $(<$LOCKFILE)"
/bin/rm -f $TMPFILE
exit
fi
trap "/bin/rm -f ${TMPFILE} ${LOCKFILE}" 0 1 2 3 15
# find my gitconfig
CFGFILE="/local/share/DOTfiles/DOTgitconfig.$myuser"
if [ ! -s $CFGFILE ]; then
echo "No personal /local/share/DOTfiles/DOTgitconfig found."
exit
fi
# roll it in
cp $CFGFILE $HOME/.gitconfig
# execute git
/usr/bin/git "$@"
# roll it back in case of changes
cp $HOME/.gitconfig $CFGFILE
# zero it out
cat > $HOME/.gitconfig << !
# This file intentionally blank for dynamic use
# The wrapper script is /local/share/bin/git
!
When two users are connected to the shared service account, git config --global user.name reports the proper name for each user. At first blush, this looks like it could make git dynamic for all users sharing one account where environment variables can't be found.
But how am I breaking things? What am I not seeing yet?
Thank you.
|
It seems like your solution would have race conditions (what happens during multiple simultaneous invocations of git?) as well as other problems (such as incorrect use of $* instead of "$@".
Instead, why don't use just set $GIT_CONFIG in each user's environment to a different file?
| Dynamic user config for git with wrapper script? |
1,548,613,238,000 |
I would like to install custom source from a git repository, but using my package manager (emerge for portage).
Background
I have installed Gentoo using EFI using Sakaki's tutorial, so I have already emerged dev-vcs/git.
The packages that I want are for installing Canonical's Snapd (background reading from Ars Technica), and their instructions are:
Gentoo
Install snap-confine.ebuild and snapd.ebuild
'# enable the snapd systemd service:
sudo systemctl enable --now snapd.service
Steps Tried that Didn't Work
Try 1
First I tried to add the prerequisite git .ebuilds as repositories by putting them in my /etc/portage/repos.conf/ directory (two separate entries). I'll post one here as an example:
[zyga-snap-confine]
# Snapd build dependency #1
# Maintainer: obscured
location = /usr/local/portage/zyga-snap-confine
sync-type = git
sync-uri = https://github.com/zyga/snap-confine-gentoo.git
priority = 60
auto-sync = yes
I synced the repos, emaint sync --repo zyga-snap-confine. And then I tried finding the packages that I wanted via both emerge --search and eix. No luck.
It tossed errors about missing layout, a master = gentoo entry...I realize that there was missing metadata, but I had high hopes.
Try 2
I finally found a reference with what to do with an ebuild. In the official Gentoo Wiki, and from other posts here (Installing Git, Curl, and Expat from Source) and here (How to package software in Funtoo/Gentoo?), I decided to:
root@Gentoo ~ # cd /opt
root@Gentoo opt # git clone https://github.com/zyga/snap-confine-gentoo.git
root@Gentoo opt # cd snap-confine-gentoo
root@Gentoo snap-confine-gentoo # ebuild snap-confine-1.0.32.ebuild manifest clean merge
However, it returned errors:
Appending / to PORTDIR_OVERLAY...
!!! Repository 'x-' is missing masters attribute in '/metadata/layout.conf'
!!! Set 'masters = gentoo' in this file for future compatibility
ebuild: /opt/snap-confine-gentoo/snap-confine-1.0.32.ebuild: does not seem to have a valid PORTDIR structure
Preferred Solution
I'm relatively new to Gentoo and am self-taught on Linux, and I couldn't find a tutorial on repo maintenance in the Gentoo forums (there is a developer's guide, but it assumes a lot of knowledge). An ideal answer will provide both the cli method (I assume using git clone ...and ./configure?) as well as the package manager version.
Even if I have to create my own git repository to add missing metadata and layout files - I would prefer to manage the snapd installation that way.
|
Based off of @likewhoa comments above, the structure of the ebuild needed to be massaged. The creators did not have recent portage structure in mind when creating their git repositories.
For Command-line
(an ebuild without portage directory structure)
Within /usr/local/portage/ I decided that snap-confine belonged under category sys-apps
From bash root prompt:
cd /usr/local/portage
git clone https://github.com/zyga/snap-confine-gentoo.git
cd snap-confine-gentoo
mkdir -pv sys-apps/snap-confine
# the Manifest file will be recreated later
rm -v Manifest
mv -v snap-confine-1.0.32.ebuild sys-apps/snap-confine/
# to avoid errors, you need your masters = gentoo reference
mkdir -v metadata
echo 'masters = gentoo' > metadata/layout.conf
cd sys-apps/snap-confine
ebuild snap-confine-1.0.32.ebuild manifest clean merge
As it turns out, the .ebuild wasn't properly formed with correct dependencies, but I think these steps provide a good tutorial - based off of:
https://wiki.gentoo.org/wiki/Basic_guide_to_write_Gentoo_Ebuilds
https://devmanual.gentoo.org/quickstart/
For Portage management
Based off of other Gentoo repositories, I recommended to the developer to create a single repo containing both the snap-confine and snapd ebuilds under the package categories sys-apps and app-emulation, respectively.
Then, we created a metadata/layout.conf file containing masters = gentoo to avoid portage compatibility complaints. Developer guidance also required that we have a profiles/repo_name file with the repo's name identified. Within each package's folder, we created a metadata.xml file and then ran repoman manifest to generate the Manifest file.
Lastly, a user needs to create an entry within /etc/portage/repos.conf/, the instructions for which are expertly detailed on the sakaki-tools github repo
| How to install custom source from git using my package manager in Gentoo? |
1,548,613,238,000 |
I had a directory such that
$ ls
$ README.md testA.c testB.c a_large_folder another_folder
my most recent add->commit->push consisted of
$ README.md testA.c
Normally, my lazy self is used to doing git add . but this time I simply wanted to add a_large_folder.
When I did,
$ git add a_large_folder
I was prompted back fatal: pathspec 'a_large_folder' did not match any files. So of course I googled "git add folders" with the first SO answer saying to git add <folder>/*.
Well, I stupidly wrote git add a_large_folder\ (notice the wrong slash). This resulted in,
>
as if it executed an interpeter. I, again being stupid, wrote :q because I've been in vim all day so I wasn't thinking about whether that would actually quit or not.
Now, all of my files after my most recent commit are gone; aka only READ.md testA.c are left in my directory. The other stuff appears as if it's been rm -rf
Not a big deal but curious why this deleted my files/folders in this directory.
|
My guess: you did not have the directory a_large_folder inside when running git add.
This is the only reason for git add a_large_folder to report:
pathspec 'a_large_folder' did not match any files
The syntax is correct and works for either for specific files as well as for a containing directory. See add.c.
If you confirmed your second command which you split over several lines, it also failed with:
fatal: pathspec 'a_large_folder:q' did not match any files
| After git, folders and files gone |
1,548,613,238,000 |
I want to tweak the Adwaita gtk3 theme a bit, and I found it here.
There are two many files to download, and I had no luck using neither git clone https://git.gnome.org/browse/gtk+/tree/gtk/theme/Adwaita nor svn export https://git.gnome.org/browse/gtk+/tree/gtk/theme/Adwaita
I'm sure that there is a way to download this dir, as I saw a guy using Adwaita theme as a base: Arc-theme
So any of you know how to download a git.gnome.org sub dir? Thank you very much for checking my issue out!
Edit 1: Answer provided by don_crissti can do the job well (I wanted to comment a thank to his post but got advised not to do that), however, if you can't install subversion, e.g. don't have root access, you can download gtk+3 source package here (at Download). It's only 10 MiB (as of ver 3.16.5).
|
You can get it with svn from https:/github.com/GNOME (svn checkout URL is available on the right side of the page). So, to get just the Adwaita sub-directory simply run:
svn checkout https://github.com/GNOME/gtk/trunk/gtk/theme/Adwaita
| How to download a sub directory on git.gnome.org? |
1,548,613,238,000 |
Since two days I'm struggling with making Gitweb work on my home server machine. I've modified so many configuration files till now, that I've decided to completely remove the Gitweb package from my server and start all over again. I've performed the apt-get purge gitweb command and then I've checked if there's still something in the file system that needs to be removed with find . -name gitweb command. It listed the /usr/share/gitweb directory so I've removed it with rm -R /usr/share/gitweb. Now when I'm trying to install the Gitweb packe from scratch I can't get the /usr/share/gitweb folder installed in my server. I've tried apt-get install --reinstall gitweb command, apt-get install gitweb, few times purged the package with apt-get remove --purge gitweb and apt-get purge gitweb, then I've updated the apt sources with apt-get update command in different sequences with the above commands but none of this ways solved my problem. Could you please help me to recover the /usr/share/gitweb folder as my Apache2 instance is not able to provide Gitweb service as this folder contained required CGI scripts to run the web app? I'm running Debian 7.8.
|
Using dpkg -c [gitweb-package.deb] in /var/cache/apt/archive/ I've noticed that contents of this package does not contain the files I was looking for, so I've checked the contents of git package and that is where I've found it, so the final solution is to reinstall the git package itself.
| Deleted gitweb folder, don't know how to reinstall it |
1,548,613,238,000 |
I have an xargs function that calls git commands recursively.
When I now call gitr log I have to hit enter until the end or q to get the next xargs call to run.
Can I tell xargs to skip user input or output everything of less at once?
|
You can call git with the --no-pager option if you want it to dump out everything without running less. Here are details from the man page:
--no-pager
Do not pipe git output into a pager.
| xargs git: skip user input |
1,548,613,238,000 |
I have such a bash script:
#!/bin/bash
cd /home/user/projekt
git config core.sparseCheckout true
git pull origin master
wait
rm -rf /var/www/project/{client,public}
cp -r /home/user/project-checkout/project/dist/* /var/www/project/
cd /var/www/project/
npm install
Since I must run the copy and the npm install commands with elevated rights, I run the bash script with sudo.
However - git pull does not work as sudo since it reads form the users .gitconfig and .sshconfig files. IT says "Please make sure you have correct access rights" as expected when doing a git sudo
How to solve? I was thinking in side the script de-elveate right for one commend - possible?
As a bonus, how can I tell my script to only pursue after line 3 has successfully finished?
|
Instead of de-elevating, you could only sudo where necessary; so in your script:
...
sudo cp ...
cd /var/www/project
sudo npm install
You can use
set -e
at the start of your script to cause any error to stop the script, which would have the desired effect on line 3. I'm not sure why you need the wait there though; git pull will only return once it's finished working.
| Running bash script with sudo, and git inside of it |
1,548,613,238,000 |
Recently git branch <tab> started showing me the following error:
$ git branch bash: -c: line 0: syntax error near unexpected token `('
bash: -c: line 0: `/usr/bin/git --git-dir=.git for-each-ref --format=%(refname:short) refs/tags refs/heads refs/remotes'
HEAD bash: -c: line 0: syntax error near unexpected token `('
bash: -c: line 0: `/usr/bin/git --git-dir=.git for-each-ref --format=%(refname:short) refs/tags refs/heads refs/remotes'
HEAD ^C
How can I fix it?
I have the following lines in my ~/.bashrc:
git() {
cmd=$1
shift
extra=""
quoted_args=""
whitespace="[[:space:]]"
for i in "$@"
do
if [[ $i =~ $whitespace ]]
then
i=\"$i\"
fi
quoted_args="$quoted_args $i"
done
cmdToRun="`which git` "$cmd" $quoted_args"
cmdToRun=`echo $cmdToRun | sed -e 's/^ *//' -e 's/ *$//'`
bash -c "$cmdToRun"
# Some mad science here
}
|
Your script does not preserve quotes. The original line executed by completion is:
git --git-dir=.git for-each-ref '--format=%(refname:short)' refs/tags refs/heads refs/remotes
by your script you get:
bash -c '/usr/bin/git --git-dir=.git for-each-ref --format=%(refname:short) refs/tags refs/heads refs/remotes'
Note the missing quotes around:
--format=%(refname:short)
Have not looked at what you actually do, but this:
quoted_args="$quoted_args \"$i\""
# | |
# +--+------- Extra quotes.
should result in something like:
bash -c '/usr/bin/git --git-dir=.git "for-each-ref" "--format=%(refname:short)" "refs/tags" "refs/heads" "refs/remotes"'
or:
quoted_args="$quoted_args '$i'"
# | |
# +--+------- Extra quotes.
bash -c '/usr/bin/git --git-dir=.git '\''for-each-ref'\'' '\''--format=%(refname:short)'\'' '\''refs/tags'\'' '\''refs/heads'\'' '\''refs/remotes'\'''
You might want to look into the %q format for printf.
| Broken git autocompletion after I have overridden the git command |
1,548,613,238,000 |
I need to check the location of the files, which were changed in the last commit. Because I will have to do this on Jenkins, this should be done using a bash script. This is the output of git whatchanged -n 1 (the command I want to use for this)
lukas @¬†leaf (~/workspace/shairweb) üêå git whatchanged -n 1
commit b4818eca9252c4a218cafefdf99540e4ebfd306d
Author: Lukas FuÃàlling <[email protected]>
Date: Tue Nov 18 13:13:43 2014 +0100
Initial release
:000000 100644 0000000... bfa384f... A pom.xml
:000000 100644 0000000... 370e9a1... A shairweb.iml
:000000 100644 0000000... 5e513a6... A src/main/java/net/k40s/shairplay/APIResource.java
:000000 100644 0000000... 45f03cb... A src/main/java/net/k40s/shairplay/FileParser.java
:000000 100644 0000000... 82aab5b... A src/main/java/net/k40s/shairplay/Main.java
:000000 100644 0000000... 20d5340... A src/test/java/net/k40s/shairplay/APIResourceTest.java
I tried doing this using grep but I believe there is a better way for doing this. How else can I parse it to get something like:
src/test/java/net/k40s/shairplay/
|
Try this way:
LASTCOMMIT=$(git log -1 --oneline | cut -f1 -d" ")
git diff-tree --no-commit-id --name-only -r $LASTCOMMIT
| Is there a way using a bash script to get the location of changes made in last git commit? |
1,548,613,238,000 |
How can I execute this search and replace on Linux without getting an error?
$ git status
On branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree clean
$ find . -not -path './.git' -type f -exec sed -i -e 's/old/new/g' -e 's/old2/new2/g' {} +
$ git status
fatal: unknown index entry format 0x74650000
The strings old and new are placeholders.
|
The -path test of find matches the entire name. From man find (emphasis mine):
-path pattern
File name matches shell pattern pattern. The metacharacters do
not treat /' or .' specially; so, for example,
find . -path "./sr*sc"
will print an entry for a directory called ./src/misc (if one
exists). To ignore a whole directory tree, use -prune rather
than checking every file in the tree. Note that the pattern
match test applies to the whole file name, starting from one of
the start points named on the command line. It would only make
sense to use an absolute path name here if the relevant start
point is also an absolute path. This means that this command
will never match anything:
find bar -path /foo/bar/myfile -print
Find compares the -path argument with the concatenation of a
directory name and the base name of the file it's examining.
Since the concatenation will never end with a slash, -path ar‐
guments ending in a slash will match nothing (except perhaps a
start point specified on the command line). The predicate
-path is also supported by HP-UX find and is part of the POSIX
2008 standard.
So your -not -path './.git' isn't actually excluding anything. For example, on one of my repositories:
$ find . -not -path './.git' -type f | grep -m5 git
./.git/COMMIT_EDITMSG
./.git/logs/HEAD
./.git/logs/refs/heads/master
./.git/description
./.git/HEAD
You wanted to use something like this, which excludes files starting with ./git/ and followed by any (or no) character(s):
find . -not -path './.git/*' -type f
But even that isn't what you really want. You want to just skip the entire ./.git sub-directory and that's what -prune is for as mentioned in the man page I quoted above:
find . -type f \( -path './.git/*' -o -print \)
| fatal: unknown index entry format after search and replace |
1,548,613,238,000 |
Why can't i clone from a repository hosted on my network?
/home/ondre $ git clone http://10.0.8.23/example.git
Cloning into 'example'...
fatal: repository 'http://10.0.8.23/example.git/' not found
I'm using Arch Linux ARM on the server with apache as a webserver. I'm sure i have no typos in the address, because when i open it in my browser it displays the directory listing, where you can find the branches/ folder, the config file etc.
Can anybody please help?
EDIT: I just did some testing and i found out something.
Terminal 1 (as the client):
/home/ondre/test $ git clone http://localhost:8000/test.git/
Cloning into 'test'...
fatal: repository 'http://localhost:8000/test.git/' not found
Terminal 2 (as the server):
/home/ondre/test $ python3 -m http.server
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
127.0.0.1 - - [25/Jul/2022 20:26:06] code 404, message File not found
127.0.0.1 - - [25/Jul/2022 20:26:06] "GET /test.git/info/refs?service=git-upload-pack HTTP/1.1" 404 -
It's probably trying to get a info/refs file that doesn't exist.
|
I found the solution! You need to cd into/the/repository.git and run
git update-server-info
on the server.
| git says "fatal: repository not found" when cloning from a lan apache server |
1,637,494,619,000 |
I'm trying to get RabbitVCS working on Kubuntu (20.04) via Thunar (1.8.14), but try as I might, nothing seems to work. Certainly it doesn't work according to their official install directions. I feel like I'm getting very close, but hit a roadblock & after literally hours of Google, am at a loss for how to proceed. Here was my process.
First, install Thunar:
sudo apt install thunar
And a couple of the rabbitvcs dependencies that are actually available in the repo:
sudo apt install python-gobject python-dbus
Next, I need to install thunarx-python. It's missing in the repo, so I install thunarx-python_0.5.1-2_amd64.deb downloaded from https://ubuntu.pkgs.org/19.10/ubuntu-universe-amd64/thunarx-python_0.5.1-2_amd64.deb.html
Likewise, python-configobj is missing in the repo, so I install the deb from https://ubuntu.pkgs.org/19.10/ubuntu-universe-amd64/python-configobj_5.0.6-3_all.deb.html
Now the basic Rabbit install:
git clone https://github.com/rabbitvcs/rabbitvcs
cd rabbitvcs
sudo python setup.py install --install-layout=deb
sudo mkdir -p /usr/share/thunarx-python/extensions
sudo cp clients/thunar/RabbitVCS.py /usr/share/thunarx-python/extensions
To see what's going on, I'll launch Thunar with thunarx-python debugging enabled:
THUNARX_PYTHON_DEBUG=all /usr/bin/thunar
The result:
thunar_extension_initialize: entered
thunarx_python_load_dir: entered dirname=/home/metal450/.local/share/thunarx-python/extensions
thunarx_python_load_dir: entered dirname=/usr/share/thunarx-python/extensions
thunarx_python_init_python: entered
thunarx-python: Setting GI_TYPELIB_PATH to /usr/lib/x86_64-linux-gnu/girepository-1.0
thunarx-python: g_module_open /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
thunarx-python: Py_Initialize
thunarx-python: PySys_SetArgv
thunarx-python: Sanitize the python search path
thunarx-python: init_pygobject
thunarx-python: import Thunarx
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/gi/__init__.py", line 129, in require_version
raise ValueError('Namespace %s not available' % namespace)
ValueError: Namespace Thunarx not available
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/gi/importer.py", line 133, in load_module
'introspection typelib not found' % namespace)
ImportError: cannot import name Thunarx, introspection typelib not found
(thunar:14773): thunarx-python-WARNING **: 11:50:40.747: thunarx_python_init_python failed
Traceback (most recent call last):
File "/usr/share/thunarx-python/extensions/RabbitVCS.py", line 41, in <module>
from gi.repository import GObject, Gtk, Thunarx
File "/usr/lib/python2.7/dist-packages/gi/importer.py", line 133, in load_module
'introspection typelib not found' % namespace)
ImportError: cannot import name Thunarx, introspection typelib not found
thunarx_python_load_dir: entered dirname=/usr/share/plasma/thunarx-python/extensions
thunarx_python_load_dir: entered dirname=/usr/local/share/thunarx-python/extensions
thunarx_python_load_dir: entered dirname=/usr/share/thunarx-python/extensions
thunarx_python_init_python: entered
Traceback (most recent call last):
File "/usr/share/thunarx-python/extensions/RabbitVCS.py", line 41, in <module>
from gi.repository import GObject, Gtk, Thunarx
File "/usr/lib/python2.7/dist-packages/gi/importer.py", line 133, in load_module
'introspection typelib not found' % namespace)
ImportError: cannot import name Thunarx, introspection typelib not found
thunarx_python_load_dir: entered dirname=/var/lib/snapd/desktop/thunarx-python/extensions
thunarx_python_load_dir: entered dirname=/usr/lib/x86_64-linux-gnu/thunarx-3/python
thunar_extension_list_types: entered
It looks like it wants the Thunarx typelib in GI_TYPELIB_PATH, which is /usr/lib/x86_64-linux-gnu/girepository-1.0. Some googling makes it seem like this should be Thunarx-3.0.typelib, where that file is included with Thunar itself (i.e. see https://www.archlinux.org/packages/extra/x86_64/thunar/files/). But it isn't. And there's no such file anywhere on my system, and search as I might, I cannot figure out where it's supposed to come from.
Any help would be greatly appreciated. I've got over 4 hours into this so far, and unfortunately still can't seem to get Rabbit working.
|
As discussed with RabbitVCS's devs here: https://github.com/rabbitvcs/rabbitvcs/issues/297, it looks like there are multiple bugs in RabbitVCS, as well as multiple inaccuracies in their install instructions.
To directly answer my own question above, I was able to get the missing typelib by downloading the rpm from https://download-ib01.fedoraproject.org/pub/epel/8/Everything/x86_64/Packages/t/Thunar-1.8.11-1.el8.x86_64.rpm, manually extracting the missing typelib, and manually moving it to /usr/lib/x86_64-linux-gnu/girepository-1.0. However, as I learned that Thunar doesn't actually support RabbitVCS's overlay icons, I ended up going with Nautilus instead. To get that working in Kubuntu, I installed like:
sudo apt install nautilus python-dbus python3-nautilus python3-configobj python3-svn
git clone https://github.com/rabbitvcs/rabbitvcs
cd rabbitvcs
sudo python3 setup.py install --install-layout=deb
sudo cp clients/nautilus/RabbitVCS.py /usr/share/nautilus-python/extensions
nautilus -q
Note: their instructions suggest installing from PPA; ignore that & install from source, as the PPA version apparently doesn't work. Their instructions also list packages nautilus-python, which didn't exist (you'll have to change to python3-nautilus), python-configobj -> python3-configobj, python-svn -> python3-svn, dulwich -> python3-dulwich, python-gtk2 -> python3-tk.
That will get it installed. At this point, it still didn't work, with error message:
TypeError: Don't know which D-Bus type to use to encode type "NoneType"
I fixed it by editing /usr/lib/python3/dist-packages/rabbitvcs/services/checkerservice.py & commenting out line 270 locale.getlocale(locale.LC_MESSAGES), as well as /usr/lib/python3/dist-packages/rabbitvcs/vcs/git/.init.py line 824. Explanation for the fix is at the github link above, but if you haven't messed with your system locale, it should work fine.
I believe they've since committed their own fix (so you may not need this last step), but this is what got it working for me, and after spending the better part of a day on this I'm just sticking with what I've got.
That leaves the only remaining broken thing: the icons in the pop-up menus are missing. Everything else seems to work: overlay icons, menu action, dialogs, etc - meaning, it's functionally up and running.
| RabbitVCS Install On Thunar / Kubuntu 20.04 |
1,637,494,619,000 |
Trying to install git to 32 bit Centos 7:
sudo yum install git
Got answer:
Requires: perl(Error)
How to fix that and install git? Why it is not trying to download perl if needed?
UPD:
Repositories list on my machine:
|
Since you provide no information about which YUM repositories you are using (yum repolist), I can only guess that the package that provides perl(Error) does not exist in any of your configured repositories.
Looking at the CentOS 7 altarch repositories for i386, I was able to find the package so you should try configuring that repository and see if it works.
| Install git to 32 bit Centos |
1,637,494,619,000 |
Is it possible to merge two same file automatically?
For example, fileA and fileB are two same files. However, fileA is on PC and fileB is on Laptop. If I run git annex import /path/to/fileA and git annex import /path/to/fileB together on each device, it will remain two different symbolic links in git archive tree after running git annex sync.
So, is there something like auto-merge tool that can remove one of those two symbolic link?
|
Git-annex stores its files based on their content hash. So if your two files fileA and fileB are identical, then they should both be recognised by git-annex as the same file. If they are not being recognised as the same file, then it suggests they might be slightly different. You could try comparing their hashes.
The git-annex docs have a tip page that explains how to combine multiple existing directories of content into a single repository, and it addresses exactly this topic.
https://git-annex.branchable.com/tips/migrating_two_seperate_disconnected_directories_to_git_annex/
| Git-annex auto merge symbolic links? |
1,637,494,619,000 |
I have two directories: Libc-825 and Libc-1044. Imagine that version 1044 is newer, but buggy. Is there a way to merge these file trees? I have there C sources with not so big differences. I have heard of using git for such purposes.
Edit: I want to get diffs of all the files where names clash, to fix bugs manually
|
You could use diff to generate a patch with new, old and conflicting files.
diff -Naur Libc-825 Libc-1044
The flags state -N treat missing files as new, -a all files are text, -u show lines before and after diff for easier identification and -r recursive. You can then apply the patch to the old directory and get the merged results.
| Merging text file directories |
1,444,899,291,000 |
I have a webserver with a git repo containing a website. I have made a CMS using PHP where PHP automatically commits to git when files are changed. I would like to track these commits (preferably in a form close to git log --name-status to show added/deleted files) using Logwatch. I have read about creating custom Logwatch services, but Logwatch is all really new to me and that didn't really get me anywhere.
|
Note: Instead of the PHP code below, if you wanted to track all git commits (and not only those committed using PHP), it should be possible to set up a post-commit hook with similar output.
Just after writing the question I came across this really simple guide. Based on that, here's what I did:
Create log directory and set permissions
I haven't tested this without setting permissions, but I assume it's needed.
sudo mkdir /var/log/gitweb
sudo chown: www-data /var/log/gitweb
PHP git log function
This line of code is run whenever I run git commit in the php code. Newlines are replaced with a custom string so that each commit is on its own line (as far as I know, Logwatch can only operate on a line-by-line basis). This will be replaced back with newlines when parsing with Logwatch.
shell_exec('(git log -1 --date=iso --name-status | awk 1 ORS="[NEWLINE_HERE]" ; echo) >> /var/log/gitweb/gitweb.log');
Logwatch log file group
# /etc/logwatch/conf/logfiles/gitweb.conf
LogFile = gitweb/*.log
Archive = gitweb/*.gz
*ExpandRepeats
Not really sure what *ExpandRepeats does, but it was in the guide I linked to.
Logwatch service
# /etc/logwatch/conf/services/gitweb.conf
Title = "Git commits"
LogFile = gitweb
Logwatch parser
This does two things:
Time filtering (it only prints lines/commits with the correct date)
Convert custrom string back to newlines (see the PHP code above)
I know absolutely zero perl (I looked at other Logwatch scripts for help), so I apologize if this is a sacrilege against all things perl-y.
use Logwatch ':dates';
my $filter = TimeFilter('%Y-%m-%d %H:%M:%S');
while (defined(my $ThisLine = <STDIN>)) {
if ($ThisLine =~ /$filter/) {
$ThisLine =~ s/\[NEWLINE_HERE\]/\n/g;
print $ThisLine;
}
}
exit(0);
Set up log rotation
# /etc/logrotate.d/gitweb
/var/log/gitweb/*log {
daily
# keep 10 old logs
rotate 10
# don't do anything if the log is missing
missingok
# don't do anything if the log is empty
notifempty
# zip the archived logs
compress
}
| How to make Logwatch track git commits |
1,444,899,291,000 |
I use Xubuntu and found that I can update packages by using apt and apt-get. But I have heard that programmers use usually git in their project to manage different version. So why Xubuntu do not use git to handle different versions of software?
|
apt and apt-get are related and very different from git.
apt is the package management tool for Debian-derived Linux distributions (including Ubuntu/Xubuntu). This is used to manage (i.e. download, install, remove, update) the binary software packages that makeup the Linux distribution you are using. This is about updating your local system software, as well as adding and removing programs.
'apt' is the command-line tool that is used to interact with the Synaptic graphical tool. Essentially, they do the same things; however, one is graphical and runs in the X-Window System and the other is run from the Linux command line.
apt-get is the command that is most-commonly used to install or update packages on your computer. apt is less-commonly used and differs from apt-get mostly in terms of output formatting. You can use man apt or man apt-get to pull up the manual pages, which will give you more details about the differences between the commands. There are also many pages online that will give you more information about how Synaptic and apt can be used.
git, on the other hand, is a versioning control system for source code for software development. Again, you can use man git for more information (if git is installed on your system). However, I wouldn't think you would need to worry much about git if you have Xubuntu and are not involved in developing software yourself.
| What is the difference between apt, apt-get and git? |
1,444,899,291,000 |
I was completing the git tutorial found here:
https://try.github.io/levels/1/challenges/7
And it said that I had to put single quotes around *.txt. I had not seen this before when using linux but thought it was peculiar. I also have seen single quotes when using html and php as a way to make sure that the string is interpretted literally instead of using special characters.
|
This is the same in the shell as in the other grammars that you mention. A single quoted string will be treated as a "string literal" (so to speak).
The difference between git add '*.txt' and git add *.txt is who's doing the matching of the pattern against filenames.
In the case of git add '*.txt', git is doing the pattern matching. Since the shell won't expand the string literal '*.txt', git add will be called with a single argument, *.txt. git then does the matching against the filenames available in the whole repository (because... git).
In the case of git add *.txt, the shell does the filename matching and will pass a list of matching filenames from the current directory to git add. Note that if there are no names matching the given pattern, the shell will (usually1) pass the pattern on to git add unexpanded. If this happens, the result will be the same as if the pattern had been quoted.
1 Usually, but see e.g. the failglob shell option in bash. See also comments to this answer.
When git add gets a filename pattern, it will add not only the files matching in the current directory, but it will add all files that matches in the whole repository (i.e. including any subdirectories). This is why the text in the lower right hand corner says
Wildcards:
We need quotes so that Git will receive the wildcard before our shell can interfere with it. Without quotes our shell will only execute the wildcard search within the current directory. Git will receive the list of files the shell found instead of the wildcard and it will not be able to add the files inside of the octofamily directory.
| What is the difference between '*.txt' and *.txt? |
1,444,899,291,000 |
The top answer to this question demonstrates that cut can be used with tr to cut based on repeated spaces with
< file tr -s ' ' | cut -d ' ' -f 8
I want to get the remotes of several Git repos in a directory and am attempting to extract the remote URL fields from each with the following:
ls | xargs -I{} git -C {} remote -vv | sed -n 'p;n' | tr -s " " | cut -d ' ' -f1
However, this results in (for example) the following output, where I can see that two consecutive spaces (Unicode code point 32) are retained:
origin https://github.com/jik876/hifi-gan.git
origin https://github.com/NVIDIA/NeMo.git
origin https://github.com/NVIDIA/tacotron2.git
(I have also using xargs with tr)
The desired output is a list of URLs, like:
https://github.com/jik876/hifi-gan.git
https://github.com/NVIDIA/NeMo.git
https://github.com/NVIDIA/tacotron2.git
What am I missing here?
|
That's a tab, not two spaces.
You can get the same output safer with a shell loop iterating over the subdirectories in the current working directory that has a .git directory, then cut the first space-delimited field (to remove the (fetch) and (push) labels at the end that git adds) and then pass that through uniq to only show a single line for each remote+URL:
for r in ./*/.git/; do
git -C "$r" remote -v
done | cut -f 1 -d ' ' | uniq | cut -f 2
The final cut -f 2 isolates the URLs by returning the 2nd tab-delimited field.
Taking into account that awk treats tabs and spaces the same (unless you use a specific separator character or pattern), we can replace the trailing pipeline with a single invocation of awk:
for r in ./*/.git/; do
git -C "$r" remote -v
done | awk '!seen[$2]++ { print $2 }'
| How to combine tr with xargs and cut to squeeze repeats |
1,444,899,291,000 |
I have two GitHub accounts. One for personal use, and another for business. Each is set up with its own SSH key gh_personal and gh_business inside ~/.ssh.
I have a personal project that sits in ~/code/bejebeje. Each time I go to work on that project, I have to remember to run the following:
eval `ssh-agent -s`
Followed by:
ssh-add ~/.ssh/gh-personal
Only then can I do things like git pull and git push.
You guessed it, I always forget to do that.
Is there a way I can tell my Linux system to do that automatically whenever I go to the directory ~/code/bejebeje?
I'm on Arch Linux.
|
You can create an ssh_config AKA ~/.ssh/config to match different addresses like the following:
Host *
Protocol 2
PreferredAuthentications publickey,password
VisualHostKey yes
Host work_gh
HostName github.com
IdentityFile ~/.ssh/id_rsa.work
IdentitiesOnly yes
ForwardAgent no
LogLevel DEBUG
Host personal_gh
HostName github.com
IdentityFile ~/.ssh/id_rsa.personal
IdentitiesOnly yes
ForwardAgent no
LogLevel DEBUG
This configuration will also not require ssh-agent nor will it try to use the agent because of IdentitiesOnly consult man ssh_config for more information on the options that you can set with ssh_config
Getting back to git, you can use the name "personal_gh" as the host name in the address you want to clone:
git clone git@personal_gh:mypersonalghuser/things.git
You can also change existing git repositories:
git remote show origin
* remote origin
Fetch URL: git@personal_gh:mypersonalghuser/things.git
Push URL: git@personal_gh:mypersonalghuser/things.git
HEAD branch: master
Remote branch:
master tracked
Local branch configured for 'git pull':
master merges with remote master
Local ref configured for 'git push':
master pushes to master (up to date)
If you have repositories that you need to push to both accounts, I would suggest adding more than one remote in git and pushing like:
git push my-dest-account-1 master
git push my-dest-account-2 master
you can add remotes with:
git remote add --help
In any case, the SSH key that gets used will be matched based on the host name part of the git address if you configured it in your ssh client configuration, usually ~/.ssh/config
| Automatically add ssh key based on directory I'm in |
1,444,899,291,000 |
I have an archive (*.xpi) file in a git repository. How can I track the archive to get a more meaningful git diff then simply Binary files ... differ?
|
Do not track .xpi file. Track the source files which are content of that .xpi.
If the plugin in question is yours - then just add directory with source files into git controlled tree.
If the plugin is someone else's and you just download the ready to use .xpi from firefox's site - do you really need track the minute changes between versions? History, readme, etc should be enough.
But if you really want, you can just unpack the archive (simple unzip will help) and do a diff on the unpacked files.
Or you can ask author of the plugin (or just read the readme file), find there this plugin is stored (github most likely) and just checkout/pull the freshest version with a full-scale diff. As additional benefit - you would get an ability to improve the plugin.
| Track archives with git |
1,444,899,291,000 |
I have been trying to install time shift from the directory I cloned from github.
I ran the following command:
cd src; make install
And then I seperatly ran:
sudo make all
Got the following result in both cases:
makefile:4: *** No msgmerge found, install it. Stop.
I then tried the command:
sudo make all
And got the following output:
cd src; make all
make[1]: Entering directory '/home/omair/timeshift/src'
makefile:4: *** No msgmerge found, install it. Stop.
make[1]: Leaving directory '/home/omair/timeshift/src'
make: *** [makefile:2: all] Error 2
After a bit of googling I installed gettext as recommended on online forums:
sudo apt install gettext
After which I again tried:
sudo make all
the result:
cd src; make all
make[1]: Entering directory '/home/omair/timeshift/src'
makefile:4: *** No valac found, install it. Stop.
make[1]: Leaving directory '/home/omair/timeshift/src'
make: *** [makefile:2: all] Error 2
After a bit of googling again, I ran:
sudo apt-get install libvala-dev
After which I gave the command I ran above one more shot:
sudo make all
The result:
cd src; make all
make[1]: Entering directory '/home/omair/timeshift/src'
makefile:4: *** No valac found, install it. Stop.
make[1]: Leaving directory '/home/omair/timeshift/src'
make: *** [makefile:2: all] Error 2
sudo apt-get install valac
then I ran:
sudo make all
the result of which is:
cd src; make all
make[1]: Entering directory '/home/omair/timeshift/src'
Package vte-2.91 was not found in the pkg-config search path.
Perhaps you should add the directory containing `vte-2.91.pc'
to the PKG_CONFIG_PATH environment variable
No package 'vte-2.91' found
/bin/bash: line 0: test: -lt: unary operator expected
Package gtk+-3.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtk+-3.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gtk+-3.0' found
/bin/bash: line 0: test: -gt: unary operator expected
#timeshift-gtk
valac -X -D'GETTEXT_PACKAGE="timeshift"' \
--Xcc="-lm" --Xcc="-O3" -D VTE_291 \
Core/*.vala Gtk/*.vala Utility/*.vala Utility/Gtk/*.vala \
-o timeshift-gtk \
--pkg glib-2.0 --pkg gio-unix-2.0 --pkg posix \
--pkg gee-0.8 --pkg json-glib-1.0 \
--pkg gtk+-3.0 --pkg vte-2.91
error: Package `gee-0.8' not found in specified Vala API directories or GObject-Introspection GIR directories
error: Package `vte-2.91' not found in specified Vala API directories or GObject-Introspection GIR directories
Compilation failed: 2 error(s), 0 warning(s)
make[1]: *** [makefile:52: app-gtk] Error 1
make[1]: Leaving directory '/home/omair/timeshift/src'
make: *** [makefile:2: all] Error 2
I am at the verge of giving up here.
Edit: I have also tried it after installing libgtk2.0-dev:
sudo apt-get install libgtk2.0-dev
Also tried:
Install dependencies
sudo apt install -y g++ libgtk-3-dev gtk-doc-tools gnutls-bin \
valac intltool libpcre2-dev libglib3.0-cil-dev libgnutls28-dev \
libgirepository1.0-dev libxml2-utils gperf build-essential
Get and install vte-ng as per instructions I've found somewhere:
git clone https://github.com/thestinger/vte-ng.git
echo export LIBRARY_PATH="/usr/include/gtk-3.0:$LIBRARY_PATH"
cd vte-ng && ./autogen.sh && make && sudo make install
cd ..
|
To install Timeshift on Kali Linux you only need to download it from the repositories.
Remove the version you installed yourself by using apt purge timeshift.
If you were able to install the package from source, then you can run timeshift-uninstall to remove the software. I would also recommend that you clean up the directories containing the source code and binaries to confirm that it is removed from your system.
Confirm that your Kali Linux /etc/apt/sources.list only contains the following:
deb http://http.kali.org/kali kali-rolling main non-free contrib
As pointed out in the Official Kali Linux documentation, you can run the following to confirm this is the case:
grep -v '#' /etc/apt/sources.list | sort -u
Additionally you should have nothing present inside /etc/apt/sources.list.d.
Update your system with apt update and apt upgrade.
Then install Timeshift with apt install timeshift.
Now Timeshift will be installed and managed with your package manager. On a Debian-based system this is the easiest way to keep package and system compatibility high and prevent any package mismatch or FrankenDebian type issues.
Kali Linux is a rolling release, so do not be surprised if bleeding-edge upstream packages and libraries introduce system instability or other issues. It is largely designed as a disposable pentesting distro with the most common security tools preinstalled.
Best of Luck!
| Cannot install Timeshift on Kali |
1,444,899,291,000 |
Normally when I commit a change to a submodule in Git (and if that's the only change), I will provide the result of git diff <submodule-name> to the body of the commit message (with diff.submodule set to log in my git config). So the message would look something like:
Updated Core Submodule
Submodule Core eaedd3f..0721763:
< Fixed ZA-123: Crash in rendering module
< Merge 'develop' into 'master'
I've been trying to write a script that will automate this, to which I can tie to an alias in my git config. To generate the text above, ideally I'd like to run a command such as:
$ git submodule-commit Core
This would perform the following (roughly):
Stage any change to specified submodule (Core in this case)
Diff the change to the submodule and store that output text for the message generated later
Run git commit and provide the subject line (Updated $1 Submodule, or something of that sort, where $1 is Core in this example).
Add the stored diff result from earlier to the commit message as well
I've not had any luck writing a simple script for this. I'm not very experienced with bash / shell scripts. Could anyone help provide an implementation that accomplishes this?
|
The key bit of syntax you're missing here is:
git commit -m "$(printf "Updated $submodule Submodule\n\n" ; git diff $submodule)"
The use of the $() form of command substitution inside double quotes sends the output of git diff... to git commit as a commit message with newlines intact.
I used printf here instead of echo to prepend the subject line since for anything even slightly complex — like dealing with embedded escapes — echo is basically nonportable, for historical reasons.
The rest of the script is left as an exercise to the student. :)
| A bash script that can automate git commit message contents |
1,444,899,291,000 |
I have
git () { [ $1 = commit ] && command git commit -v "${@:2}" || command git "$@"; }
It makes git commit have -v as a default, otherwise pass on the params and do whatever the git command is.
But it seems like something that could be shortened?
fyi, I'm slimming down my .bashrc file. Down to 28 (mostly readable still) lines so far.
|
Here's a way to not repeat then command git part:
git () {
if [ "$1" = commit ]; then set commit -v "${@:2}"; fi
command git "$@"
}
Note that you should not use $1 without double quotes. Always use double quotes around variable substitutions unless you know why you need to leave them out.
Don't use && and || as shortcuts. It's cute, and it might save a few characters, but saving characters is pointless. Readability is important, and if states the intent of the code in a clearer way.
You may want to define an alias in your git configuration instead (but you can't shadow an existing command this way, you need to use a different name), with something like this in ~/.gitconfig:
[alias]
co = commit -v
| Is there a way to make git commit have -v as a default? |
1,444,899,291,000 |
let's say I want to get this branch the same way I get the latest one, using git clone git://github.com/raspberrypi/linux.git. How do I do it?
|
You need to add the branch tag to the clone process.
git clone -b rpi-3.2.27 https://github.com/raspberrypi/linux.git
| Getting branch from git |
1,444,899,291,000 |
This is part of a larger script but I distilled the problem down to this:
cm_safe(){
git push | while read line; do
echo "cm safe push: $line"
done;
}
I want to prepend git output, so it would look like:
cm safe push: Everything up-to-date
but instead I just get:
Everything up-to-date
Is git writing to the tty or something directly? I dunno what's going on.
|
git push writes to stderr so you would have to redirect that to stdout in order for it to be sent over the pipeline:
cm_safe(){
git push 2>&1 | while IFS= read -r line; do
echo "cm safe push: $line"
done
}
Alternatively you could do:
git push |& while IFS= read -r line; do
I recommend reading What are the shell's control and redirection operators? for more information.
| How to prepend lines to git command output |
1,444,899,291,000 |
Say I type git help to learn about the merge command. I don't want to read all the output just the lines that contain merge and their surrounding lines.
I thought this would be a common question but couldn't find it. I think grep can be used somehow to do this.
|
Yes, grep can do something like this: its -C option will show the context of a match. Thus
git help | grep -C2 merge
will show lines containing “merge”, with two lines of context above and below.
I find it more convenient to use less:
git help | less
then search using /.
git help
won’t tell you much though, you’ll need
git help merge
which will open the relevant manpage for you.
Some terminal emulators also allow searching after the fact; for example, GNOME Terminal has a Search menu, and you can press CtrlShiftF to start a search.
| How can I search terminal output? |
1,444,899,291,000 |
I'm trying to make a git alias that shows branch names and descriptions. There is no dedicated command or switch to get the description of a branch; it must be sussed from configuration. However I want to get a list of all branches and their descriptions (if they have one).
One can get a sort of "raw data" like so:
$ git config -l
core.symlinks=false
core.autocrlf=false
core.fscache=true
color.diff=auto
So the entries that I'm interested in look like this:
branch.featureA.description=Mail templates
branch.featureB.description=Something else
Which I can get with this pipeline: git config -l | grep description | grep \^branch. For my desired output, I want this:
featureA Mail templates
featureB Something else
So one way to express this is that I want the second "column" after the period, and the first "column" after the equal sign. Or, I want .branchname. and .description= removed. I'm not sure the best way to go, but I tried using awk to treat the string as columns. I can get part of what I want with different delimiters:
$ git config -l | grep description | grep \^branch. | awk -F '.' '{ print $2 }'
featureA
featureB
$ git config -l | grep description | grep \^branch. | awk -F '=' '{ print $2 }'
Mail Templates
Something else
However trying to combine the two delimiters doesn't seem to work:
$ git config -l | grep description | grep \^branch. | awk -F '.=' '{ print $2 }'
Mail templates
Something else
How can I parse the data I want out of the string?
|
I would probably use sed for this:
sed -n '/^branch/{ s/[^.]*\.//; s/\.[^=]*=/ /p; }'
This catches any line starting with the string branch and for each of those lines
deletes everything up to and including the first dot, then
replaces everything from the first remaining dot up to and including the first = character with a space.
The modified line is then printed. Any other line is discarded.
With awk:
awk -F '=' '/^branch/ { split($1, a, "."); print a[2], $2 }'
This treats the input as delimited by the = and then splits the first part on dots. It then prints the second dot-delimited string and the bit after the =.
This would fail if the line contains more than one = (the bit after the second = would be lost).
| trouble with two delimiters in awk |
1,444,899,291,000 |
This is on a Mac but I figure it's a Unixy issue.
I just forked a Github repo (this one) and cloned it to a USB stick (the one that came with the device for which the repo was made). Upon lsing I notice that README.md sticks out in red. Sure enough, its permissions are:
-rwxrwxrwx 1 me staff 133B 15 Jun 08:59 README.md*
I try running chmod 644 README.md but there's no change. What's going on here?
|
Because the 'executability' of a file is a property of the file entry on UNIX systems, not of the file type like it is on Windows.
In short, ls will list a file as being executable if any of the owner, group, or everyone has execute permissions for the file. It doesn't care what the file type is, just what the permissions are. This behavior gives two significant benefits:
You don't have to do anything special to handle new executable formats. This is particularly useful for scripting languages, where you can just embed the interpreter with a #! line at the top of the file. The kernel doesn't have to know that .py files are executable, because the permissions tell it this. This also, when combined with binfmt_misc support on Linux, makes it possible to do really neat things such as treating Windows console programs like native binaries if you have Wine installed.
It lets you say that certain files that are technically machine code can't or shouldn't be executed. This is also mostly used with scripting languages, where it's not unusual to have libraries that are indistinguishable in terms of file format form executables. So, using the python example above, it lets you say that people shouldnt' be able to run arbitrary modules form the Python standard library directly, even though they have a .py extension.
However, this all kind of falls apart if you're stuck dealing with filesystems that don't support POSIX permissions, such as FAT (or NTFS if you don't have user-mappings set up). If the filesystem doesn't store POSIX permissions, then the OS has to simulate them. On Linux the default is to have read write and execute permissions set for everyone, so that users can just do what they want with the files. Without this, you wouldn't be able to execute scripts or binaries off of a USB flash drive, because the kernel doesn't let you modify permissions on such filesystems per-file.
In your particular case, git stores the attributes it sees on the files when they are committed, and the original commit of the README.md file (or one of the subsequent commits to it) probably happened on a Windows system, where such things are handled very differently, and thus git just stores the permissions as full access for everyone, similarly to how Linux handles fiesystems without permissions support.
| Why would README.md show up as an executable? |
1,444,899,291,000 |
In Bash, given a command which takes a pathname as an argument, does file expansion happen to the pathname argument before the command can see the value of this argument?
My question comes from my comment about what does . refer to in the following git commands:
git --git-dir=/path/to/my/repo/.git add .
git --work-tree=/a/path --git-dir=/path/to/my/repo/.git add .
git -C /path/to/my/repo add .
The answer that my comment replies to and the following comments say that . doesn't always mean the directory where I run the command. But I don't understand it, because I think file expansion happens before the command can see the value of the argument.
|
All expansions take place before the command is run. How the command interprets what it gets is entirely up to it. None of your example commands have any expansions involved - . is not expanded by the shell.
The git command uses . after changing directories according to your options, so . won't be your current directory. Nor will tar archive my current directory in the following command:
tar -C etc -c .
| Should file expansion happen before a command sees its argument? |
1,444,899,291,000 |
I'm trying to parse the output of commands run in a bash loop. Here is an example:
$ for i in `git log --format='%H'`; do echo $i ; git branch --contains $i; done | head -n 8
5f11ce7da2f9a4c4899dc2e47b02c2d936d0468e
* foobar
e1c3f6fabd45715b527a083bc797e9723c57ac89
dev1
* foobar
7053e08775d2c1da7480a988a235e445799cbca5
dev1
* foobar
The command git log --format='%H' prints out only the commit ID for each Git commit. The command git branch --contains $i prints out which Git branches contain the commit.
I'm trying to find the latest git commit that is not on branch 'foobar'. I would like to echo $i for the first branch whose output of git branch --contains $i contains a line that does not start with the * character, which specifies "current branch". What Bash documentation should I be reading?
Note that I am aware of other solutions to this problem. However, I plan on making additions that the other answers do not account for. Furthermore, this is how I improve my Bash scripting abilities.
|
Something like this might be what you want.
for i in $(git log --format='%H'); do
branch="$(git branch --contains $i|awk 'NR==1{print $1}')"
[ "$branch" != "*" ] && echo "commit '$i' is in branch '$branch'"
done
Prints the commit and its branch if not the current branch.
| Parse lines of output from bash loop |
1,444,899,291,000 |
When I try to verify the integrity of git-man-pages package I downloaded from "http://code.google.com/p/git-core/downloads/detail?name=git-manpages-1.8.4.tar.gz&can=2&q=" it fails with error.
Command which i ran: md5sum -c git-manpages-1.8.4.tar.gz
Error displayed:
md5sum: git-manpages-1.8.4.tar.gz: no properly formatted MD5 checksum lines found
I also tried entering the checksum value of git-manpages that i found in site in a file called checksum in the following format
8c67a7bc442d6191bc17633c7f2846c71bda71cf git-manpages-1.8.4.tar.gz
and then running the
Command: md5sum -c checksum
Error displayed:
md5sum: checksum: no properly formatted MD5 checksum lines found
|
If you just want to compute the checksum of the file you downloaded you should leave the -c out. Apologies if I didn't understand your question right. For example:
$ md5sum git-manpages-1.8.4.tar.gz
e3720f56e18a5ab8ee1871ac9c72ca7c git-manpages-1.8.4.tar.gz
md5sum also expects 2 spaces between checksum and file name in files to be used with -c, just like in the output above.
| md5sum check fails for git-man-pages.tar.gz package |
1,444,899,291,000 |
I've been trying to update Git for a while. I'm currently stuck on 1.7.3.4, and I've tried updating to 1.7.4.x, and 1.7.5.x but it never works.
Today I compiled and installed Ruby 1.9.2, but it still shows up as 1.8.7.
I'm running 10.6.7 on a MacBook Pro.
I have no idea why it won't update. Any ideas? :(
|
Often, software compiled from source will install to /usr/local/bin. This is probably where you are installing your locally-compiled Ruby.
A common “downloadable” Git for Mac OS X is the git-osx-installer pre-built version. It installs to /usr/local/git/bin (though I suppose you might have downloaded some other variant).
Neither of those directories are in the default PATH environment variable, so neither will be used when you type ruby or git into your shell.
However, the system-bundled Ruby (version 1.8.7) and the Git that comes with Xcode 4 (1.7.3.4, as I have read) are installed in /usr/bin, which is in the default PATH.
You probably just need to adjust your PATH in your shell initialization files. Just put your locally installed directories first.
If you are using bash (the default), add the following to your .bashrc:
PATH=/usr/local/bin:/usr/local/git/bin:$PATH
and make sure you have the following in your .bash_profile or .bash_login (use whichever exists or .bash_profile if neither exist):
source ~/.bashrc
| Ruby and Git refuse to update. (Mac) |
1,444,899,291,000 |
I have a local git version control installed on RedHat 8 server, and when I run git add * it asks me to provide the sudo permissions which is sudo git add * and this makes the add run with the root for me and all the other team do the same.
So, when I run git log it provides me with the list of changes however the changer for all changes is the root. How to make each user run with its own credentials?
|
So, what's happening here is that you try to use git on files that aren't accessible by your (non-root) user.
That might be because the actual source files don't belong to you, or because the .git directory doesn't – which definitely happens once someone (you maybe?) used sudo git.
Git is not meant for multi-user repo checkouts. You're simply using git in a way that it was specifically designed to not be used in¹.
You must stop using git the way you're currently using it. It will lead to someone finally breaking something, the repo will need to be repaired. And that's the best case – I've seen people do exactly what you're doing, and they ended up irreparably separating the state that's tracked from the checkout, and loss of source code was the result. All because they insisted on using sudo and a single shared repo, instead of taking the 30 seconds to actually clone that repo, work locally and git push their changes upstream.
Git's design is such that each user can have its own, independent, 100% owned by them, clone of the "upstream" repo. Each user should work on their own copy. There is no shared copy.
If you need something like "I make changes and they need to take effect on a shared infrastructure", then you do something like this:
Somewhere on a server, you set up a new user (that user is commonly just called git), and you give all the team members SSH access by adding their SSH public keys to the user's $HOME/.ssh/authorized_keys.
You create a bare repo in the home directory of that new user, git init --bare mygitproject.
You add a script as post-receive git hook. Git will automatically execute that script the moment someone pushes something to that repo.
3.1. In that script, you can, for example, do something like "if that push was to the main branch of the repo, check out all the files into a target directory." For example, git --work-tree=/etc/apache2 checkout main would be something you find in that script if you wanted to keep your apache2 configuration in git.
All the individual users use git clone to get their local and own copy of the repo. They work on there, git commit and finally git push. No root / sudo involved at all!
Of course, what the above does is implement a tiny "continuous deployment" (CD) environment. More might software exists that can do all this for you, including managing users that can push and so on. Forgejo is one of such.
¹ Git supports what is called shared repos, indeed, with a long list of caveats, and a strict requirement that you understand the ramification of the underlying user permission issues. The way you describe your error, that really is not the scenario you and your colleagues are in; I'd very strongly recommend against using that option, and if asked about usage details, will not elaborate.
The official git manual puts it like this (my paraphrasing):
You can do that, which will be especially appealing if you're used to 41 year old revision control system architecture and slow at learning new things. But not doing that only has advantages, including avoiding that someone accidentally breaks everything.
| Local Git multi users issue |
1,444,899,291,000 |
I created a script like shown here to simplify clearing out my git remotes.
Created the file with the format git-{command} and made it executable.
Included file in PATH.
The script seems to work if I directly execute it. But as far as I can understand, I should be able to run these scripts directly from git. i.e., ./git-clean-remote origin works, but git clean-remote origin does not.
But as you can see from the screenshot below, I cannot seem to get the command to work. Am I missing something obvious?
|
I think you need to re-edit because both commands are the same (not matching the image)
the PATH variable should not have the full executable in it, just the path to it, i.e. ${HOME}/.dotfiles/git/
| Unable to use custom git commands on Mac |
1,444,899,291,000 |
I get the following error when trying to uncompress piped tar file with the following command :
$ git archive --format=tar 0af62b1 | tar -xf -C /the/path/here/
tar: -C: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
The first part git archive --format=tar 0af62b1 outputs a tar file, printed on the screen. This output can be captured in a file by using the parameter --output file_name.
In the second part I'm trying to extract the content of the file into the indicated path. When run separately both work perfectly git archive 0af62b1 --output file_name followed by tar -xf file_name -C /the/path/here/.
Why piping is not possible in this case and how do I know if a certain command accepts piped input?
|
I would try to pipe your git into tar -xf - -C /the/path/here/ where - is synonymous of the standard input. Or simpler tar -xC /the/path/here (- is the default file).
| How to pipe a file as input to tar command |
1,444,899,291,000 |
I have noticed that Git clone can easily download all files of a GitHub repository to to a directory named exactly as the GitHub repository (without having to deal with archives).
If a directory with the same of the repository already exists, Git will throw an error:
fatal: destination path 'REPOSITORY_NAME' already exists and is not an empty directory.
In such case, perhaps a good coping with it is to somehow clone anyway but to just save the data in a directory with a different name.
|
git clone takes a directory name on the command line too. From man git-clone:
NAME
git-clone - Clone a repository into a new directory
SYNOPSIS
git clone [--template=<template_directory>]
[-l] [-s] [--no-hardlinks] [-q] [-n] [--bare] [--mirror]
[-o <name>] [-b <name>] [-u <upload-pack>] [--reference <repository>]
[--dissociate] [--separate-git-dir <git dir>]
[--depth <depth>] [--[no-]single-branch] [--no-tags]
[--recurse-submodules[=<pathspec>]] [--[no-]shallow-submodules]
[--[no-]remote-submodules] [--jobs <n>] [--sparse]
[--filter=<filter>] [--] <repository>
[<directory>]
E.g.
$ git clone https://git.savannah.gnu.org/git/bash.git blahblah
Cloning into 'blahblah'...
| Git clone; how to deal with directory clashes? |
1,444,899,291,000 |
I'm new in Linux and i am using Ubuntu 20.04.2.0 LTS. I am tring to install git with following steps in this site. When I run sudo apt update or sudo apt-get update command that returns this errors:
sudo apt update
Get:1 http://security.ubuntu.com/ubuntu focal-security InRelease [109 kB]
Hit:2 http://dl.google.com/linux/chrome/deb stable InRelease
Err:3 http://tr.archive.ubuntu.com/ubuntu focal InRelease
Temporary failure resolving 'tr.archive.ubuntu.com'
Err:4 http://tr.archive.ubuntu.com/ubuntu focal-updates InRelease
Temporary failure resolving 'tr.archive.ubuntu.com'
Err:5 http://tr.archive.ubuntu.com/ubuntu focal-backports InRelease
Temporary failure resolving 'tr.archive.ubuntu.com'
Fetched 109 kB in 36s (3.074 B/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
All packages are up to date.
W: Failed to fetch http://tr.archive.ubuntu.com/ubuntu/dists/focal/InRelease Temporary failure resolving 'tr.archive.ubuntu.com'
W: Failed to fetch http://tr.archive.ubuntu.com/ubuntu/dists/focal-updates/InRelease Temporary failure resolving 'tr.archive.ubuntu.com'
W: Failed to fetch http://tr.archive.ubuntu.com/ubuntu/dists/focal-backports/InRelease Temporary failure resolving 'tr.archive.ubuntu.com'
W: Some index files failed to download. They have been ignored, or old ones used instead.
I have also tried sudo apt-get update
I have tried this solution in https://askubuntu.com/ but changing DNS is not solved my Temporary failure resolving 'tr.archive.ubuntu.com'and according to second part of this solution I shall remove deb http:/archive.canonical.com/ natty backports line from my source.list but i already don't have this.
My sources.list
|
The servers seem to be down as pinging fails:
ping tr.archive.ubuntu.com
The simplest circumvention would be to directly use archive.ubuntu.com, i.e. removing the tr. prefix.
Ubuntu archives usually have a local mirror to ease the load on the main servers and reduce traffic around the globe for speed reasons. Why the tr.-mirrors are down and if that is permanent cannot be said. Usually they should work.
| How can I get rid of this error when apt update and instal git |
1,444,899,291,000 |
I have the following functions in my .bashrc which just creates a python project with venv and creates gitignore and readme, after I initialise with git as: git init python
__git_init_folder_for_python(){
local README='
### Description
Python3 Project
### Installation```
python3 -m venv ./
source bin/activate
pip3 install -r requirements.txt
```'
local GITIGNORE='
### For venv
__pycache__/
bin/
lib/
include/
pyenv.cfg
'
## $(command -v git) fails
$(which git) init \
&& python3 -m venv ./ \
&& . bin/activate \
&& pip3 freeze > requirements.txt
[[ ! -f "README.md" ]] && printf "%s\n" "$README" > README.md
[[ ! -f ".gitignore" ]] && printf "%s\n" "$GITIGNORE" > .gitignore
}
__make_git_folder(){
case "$1" in
python )
__git_init_folder_for_python
;;
* )
echo "not found"
esac
}
git(){
local ARG1="$1"
local ARG2="$2"
case "$ARG1" in
'init' )
if [[ "$ARG2" == "python" ]]; then
__make_git_folder "$ARG2"
else
$(which -a git | head -1) "$ARG1" # $(command -v git) fails
fi
;;
*)
$(which -a git | head -1) "$@" # $(command -v git) fails
esac
}
I think I know why it is happening because I have overwritten git as bash function. so:
$ command -v git
git
as:
$ type git | head -1
git is a function
But, if I use which instead, even after overwriting git as function, it returns the correct path.
$ which git
/usr/local/bin/git
How can I make command -v return the correct path without explicitly declaring the path before the git function? Is it a bad practice to overwrite functions like this? If so, what is the correct approach?
|
How can I make command -v return the correct path
You can't. If you want the full path use which. However, I don't think you need this full path. Just call
command git ...
without the -v flag. The flag doesn't have an intuitive behavior and it doesn't print what command without the flag would do.
But, if I use which instead, even after overwriting git as function, it returns the correct path.
which is an external program. It does not know of bash functions. command is a builtin.
| command -v <foo> returns wrong result after overwriting <foo> as function |
1,597,610,216,000 |
I'm a newbie to the Linux world as well as to git. I recently set up version control to manage my dotfiles by creating a Git repository called 'dotfiles'. However, whenever I commit any changes, I am asked for my Git user name and password and then my user name and email address gets automatically inserted into my .gitconfig file under the user section. For now, this is fine as the Git 'dotfiles' repository is private, but in the future, I may make this repository public. If so, I do not want my user name and email address to be shown in .gitconfig. How do I prevent this from happening?
I noticed in Matthias Bynens' .gitconfig file, there is no user section and there is the following commit section:
[commit]
# https://help.github.com/articles/signing-commits-using-gpg/
gpgsign = true
I also noticed that in Anish Athalye's .gitconfig file, there is no commit section but the user section contains this:
[user]
useConfigOnly = true
|
Git requires that you provide a name and an email address in order to commit. These values are inserted in every commit that you make and they must be nonempty and meet some basic validation. Conventionally, the name is your personal name, but that isn't required by Git itself, although projects you contribute to may require it.
However, having said that, you don't have to provide them in ~/.gitconfig, or even in any config file at all. Git will first of all read from the environment variables GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, GIT_COMMITTER_NAME, and GIT_COMMITTER_EMAIL if they exist. However, usually this is not a good idea because it overrides values when you use git commit --amend, and you want to use another technique.
git-commit(1) explains the other options:
In case (some of) these environment variables are not set, the information is taken from the configuration items user.name and user.email, or, if not present, the environment variable EMAIL, or, if that is not set, system user name and the hostname used for outgoing mail (taken from /etc/mailname and falling back to the fully qualified hostname when that file does not exist).
The author.name and committer.name and their corresponding email options override user.name and user.email if set and are overridden themselves by the environment variables.
The typical usage is to set just the user.name and user.email variables; the other options are provided for more complex use cases.
I typically leave my name in user.name and set EMAIL appropriately in my shell config. Do note that some programs, most notably Homebrew, are broken and filter EMAIL from the environment, so this won't work in all circumstances. It isn't a good idea to rely on the system GECOS field and mail setup being correct, because usually it isn't.
Finally, note that you can use a different config file, usually in ~/.config/git/config to store values that you don't want to store in the main ~/.gitconfig or check in to your dotfiles repository. I do this for values like commit.gpgsign, since not all systems I use have my private keys and can sign commits, and therefore it's system dependent whether I can sign and what keys I use.
| How to prevent automatic insertion of your Git user name and email address in gitconfig file? |
1,597,610,216,000 |
I'm trying to install Git using the following commands:
sudo apt-get install git-core
and
sudo apt-get install git
Both don't seem to work. It seems that it can't find some packages.
This is the result for both commands:
My sources list:
# deb http://ftp.de.debian.org/debian jessie main
deb http://ftp.de.debian.org/debian jessie main non-free contrib
deb-src http://ftp.de.debian.org/debian jessie main non-free contrib
deb http://old-releases.debian.org/ jessie/updates main contrib non-free
deb-src http://old-releases.debian.org/ jessie/updates main contrib non-free
# jessie-updates, previously known as 'volatile'
deb http://ftp.de.debian.org/debian jessie-updates main contrib non-free
deb-src http://ftp.de.debian.org/debian jessie-updates main contrib non-free
deb http://ftp.debian.org/debian jessie-backports main
deb http://mirrors.digitalocean.com/debian jessie main contrib non-free
deb-src http://mirrors.digitalocean.com/debian jessie main contrib non-free
# jessie-updates, previously known as 'volatile'
deb http://mirrors.digitalocean.com/debian jessie-updates main contrib non-free
deb-src http://mirrors.digitalocean.com/debian jessie-updates main contrib non-free
deb http://packages.dotdeb.org jessie all
deb-src http://packages.dotdeb.org jessie all
deb http://ftp.debian.org/debian stretch-backports main
deb-src http://ftp.debian.org/debian stretch-backports main
My Linux version: Debian GNU/Linux 8 (jessie)
What are the correct package urls for Git?
|
Remove all lines in your sources.list and add the following lines
deb http://ftp.us.debian.org/debian/ jessie main contrib non-free
deb-src http://ftp.us.debian.org/debian/ jessie main contrib non-free
and don't forget apt-get update
| Debian 8 - Can't install Git [duplicate] |
1,597,610,216,000 |
I tried the following:
$ git clone git://anonscm.debian.org/collab-maint/angband.git
Cloning into 'angband'...
fatal: unable to connect to anonscm.debian.org:
anonscm.debian.org[0: 194.177.211.202]: errno=Connection refused
I thought perhaps collab-maint might have moved to salsa.debian.org (the gitlab instance), but didn't find it there as well.
https://salsa.debian.org/explore/groups?filter=collab-maint
Can anybody tell me what am I doing wrong. FWIW I'm behind no proxy or firewall
|
As indicated at the old address, Alioth has been discontinued. The Angband repository has not been migrated to Salsa, the replacement service, but you'll find an archive here.
I would suggest that you use wget to download the file
wget https://alioth-archive.debian.org/git/collab-maint/angband.git.tar.xz
then
tar -xJf angband.git.tar.xz
After that:
git clone /path/to/angband.git
| Unable to connect to angband Debian repo |
1,597,610,216,000 |
I'm trying to push code using git to my remote server, but I get the error:
fatal: protocol error: bad line length character:
8
I researched this bug and it turns out my .bashrc file that echos out a welcome screen is causing this error. What I would like to do is determine if this is a git push and to NOT display the welcome screen, or only display the screen when logging into SSH with no directory parameter:
ssh [email protected]:/deployment/bare-git-repo
Here is the relevant lines in .bashrc:
if [ -e ./.doc ]
then
cat ./.doc
pm2 list
fi
Thanks in advance!
|
I don’t think there’s anything specific to git push hooks on the server, that you could use, but you could check whether you’re outputting to a terminal:
if [ -t 1 ] && [ -e ./.doc ]; then
cat ./.doc
pm2 list
fi
This will deal with a number of other cases where outputting the contents ./.doc doesn’t serve much purpose and could cause problems.
| .bashrc is causing git push to fail |
1,597,610,216,000 |
I'm trying to use version control in my music folder to track how I sort it and when I add/delete music. I only need the metadata and not the contents in the repo.
To achieve this, I'm using tree to maintain two text files that are in .list in the root directory for the repo.
This is the script run by cron every 15 minutes:
cd /home/user/folder/ && tree -faRn -o /home/user/folder/.list/1
cd /home/user/folder/ && tree -faRhupsDn --du -o /home/user/folder/.list/2
git -C /home/user/folder add .list
git -C /home/user/folder commit -m $a
It's also monitoring the .git folder (!) and this means that it's committing everytime the script runs. Should I add .git to a gitignore? Why is it watching the .git folder anyway? is it because my directory is named .list? Do I need to double quote it? .list isn't a git repo.
Thanks, kusalananda!
Here's the modified (and working!) script:
cd /home/user/folder/ && tree -faRn -I '.git|.list' -o /home/user/folder/.list/1
cd /home/user/folder/ && tree -faRhupsDn -I '.git|.list' --du -o /home/user/folder/.list/2
git -C /home/user/folder add .list
git -C /home/user/folder commit -m $a
|
It is tree that looks into the .git directory.
You will want to tell tree to ignore the .git directory. On the Ubuntu machine that I have access to, this is done with
tree -I '.git' ...other options...
You may also want to have it ignore the .list folder.
| git does not exclude .git directory |
1,597,610,216,000 |
Now here is the commit id 41f9f4e392ab50db264e0328de7d69f1f10646eb, I want to get this commit id code which were modified only.
I use git show 41f9f4e392ab50db264e0328de7d69f1f10646eb to see modified files, how can I download these both after modified and before modified version via Linux git command? In a word, I just want to compare the differences from before and after commit id 41f9f4e392ab50db264e0328de7d69f1f10646eb to merge code easily.
Any idea will be helpful, thanks in advance.
|
Thanks all, I have found the correct way, here it is.
#!/bin/bash
from_id=$1
to_id=$2
#echo $from_id
#echo $to_id
diffpath='patch/diff.log'
newpath='patch/new/'
oldpath='patch/old/'
rm -rf patch
mkdir -p $newpath
mkdir -p $oldpath
git diff $from_id $to_id --raw > $diffpath
cat $diffpath | while read line
do
#echo =====================================
#echo $line
OLD_IFS="$IFS"
IFS=" "
arr=($line)
IFS="$OLD_IFS"
#echo ${arr[4]}
filepath=${arr[4]##* }
#echo $filepath
newid=${arr[2]%%...}
#echo $newid
oldid=${arr[3]%%...}
#echo $oldid
if [ "$newid"x != "0000000"x ]; then
newfilepath=${newpath}${filepath}
echo $newfilepath
dirpath=${newfilepath%/*}
echo $dirpath
mkdir -p ${dirpath}
git cat-file -p $newid > ${newfilepath}
fi
if [ "$oldid"x != "0000000"x ]; then
oldfilepath=${oldpath}${filepath}
echo $oldfilepath
dirpath=${oldfilepath%/*}
echo $dirpath
mkdir -p ${dirpath}
git cat-file -p $oldid > ${oldfilepath}
fi
done
You will found the new directory named patch in current working directory after doing this.
| How to get the modified files(before and after) from git version server? |
1,597,610,216,000 |
I have tried several ways to save into a log file 'git fetch output' from terminal, through a bash file but without success, like,
git fetch origin > output.log
or even adding output.log in the front of the bash script where i have 'git fetch origin'.
With command script is the only way i have to record all the info into a txt file through '>', but i would have to insert it manually and it stops when i try to use it inside of a bash file to let me introduce commands, dont know if there is a way to use a bash file to insert 'git fetch origin' command inside of script command.
This is a sample of how the output in terminal is after i execute 'git fetch origin' command,
Xserver$ git fetch origin > output.log
remote: Counting objects: 14, done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 14 (delta 5), reused 0 (delta 0)
Unpacking objects: 100% (14/14), done.
From https://bitbucket.org/x/test
* [new branch] branch1 -> origin/branch1
* [new branch] branch2 -> origin/branch2
* [new branch] branch3 -> origin/branch3
* [new branch] branch4 -> origin/branch4
* [new branch] master -> origin/master
Is there a way to save this output to a txt file?
|
Looks like git prints the output to stderr, so you should use >&.
Example: git fetch -v >& test.txt
| Save into file git fetch terminal output |
1,597,610,216,000 |
I'm trying to understand what does this code means:
function git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \1/'
}
but I don't get it. Someone said this code is made to make a configuration to your terminal, I don't really understand this configuration.
Could someone explain me?
|
This function will return a name of your current git branch.
Specifically:
git branch --no-color
will return the list of branches in your repository, like that:
feature/XYZ-124
* master
release/1.10
release/1.11
release/1.12
sed -e '/^[^*]/d'
Will remove any lines, except for those starting with "*" (which is a current branch)
* master
Then:
's/* (.*)/ \1/'
will extract the branch name (excluding '*' char)
master
Example
>git_branch
master
| Understanding what git branch means, in this context |
1,597,610,216,000 |
If I used the following command:
git log --pretty=format:"%ad %s%d"
the output is:
Tue Apr 26 11:29:24 2016 +0000 Updated configuration
If I do the following:
SIMPLE='--pretty=format:"%ad %s%d"'
git log $SIMPLE
then the output is as follows:
"Tue Apr 26 11:29:24 2016 +0000 Updated configuration"
I know that I can define alias gitl='git log --pretty=format:"%ad %s%d"'. But it's just bugging me to know why git is doing this.
Why does the output appear in quotes when using the variable substitution approach?
|
The difference is because of some shell quoting specialties.
If you execute either of these (they are equivalent ways of quoting in the shell)
git log --pretty=format:'%ad %s%d'
git log '--pretty=format:%ad %s%d'
git log --pretty=format:%ad\ %s%d
git log --pretty=form'at:%ad %'s%d
git log --pretty=format:%ad" "%s%d
git log --pretty=format:"%ad %s%d"
git will get two arguments, the first being log and the second --pretty=format:%ad %s%d.
If you execute
SIMPLE='--pretty=format:"%ad %s%d"'
the variable SIMPLE will have the value --pretty=format:"%ad %s%d", including the double quotes.
Now if we are in zsh and you execute
git log $SIMPLE
or in bash
git log "$SIMPLE"
git will see the second argument as --pretty=format:"%ad %s%d". (If I execute git log $SIMPLE in bash I get an error because git gets three arguments: log, --pretty=format:"%ad and %s%d").
So inside the variable you would not need the inner quotes (except if you want to pass it to eval).
| Why does git wrap my log output in quotes? |
1,597,610,216,000 |
I have setup of ubuntu Guest VM on Virtualbox on MAC HOST.
I have setup the ubuntu as server with the help
Created ssh key and put the public key on the Ubuntu and I am able to ssh
I have added remote repo like this
git remote add origin `ssh://[email protected]:/var/opt/repo-demo.git`
but I am not able do a git push to the Ubuntu VM.
However I am able to login via ssh as git user like ssh [email protected]
tried with git push --verbose doesn't help.
|
You seem to be misinpreting single quotes and backquotes, both in the commands you issued and in your question. (Seems to be typical for Apple users).
The backquote (below the tilde ~ on a US qwerty) keyboard is different from ', and if you do
`ssh://[email protected]:/var/opt/repo-demo.git`
the backquotes will make this execute as if you had put $( ) around that expression. Since bash cannot execute that expression, it will return "No such file or directory", and the git remote add origin will fail. Double
check your .git/config file, and update it by hand.
Be careful of using inappropriate quotes, especially on the Ubuntu commandline (but of course also when writing doesn't )
| git push via ssh to ubuntu VM not working but I am able to ssh to the same ubuntu |
1,597,610,216,000 |
Here is the situation. There are two machines, laptop A and workstation B. B has a fixed IP, A has a dynamic IP, and I want to avoid the need of connecting from B to A (setting up an ssh tunnel for example; for the sake of the argument, assume that ssh from B to A is not possible).
There is a git repository, /home/user/foo.git, on both machines. Problem: working on A, merge the changes on A:/home/user/foo.git and B:/home/user/foo.git. In the end, both repositories should be identical.
The simplest solution I was able to come up with is as follows:
A:~$ cd foo.git
A:~/foo.git$ git commit -a
A:~/foo.git$ ssh B
B:~$ cd foo.git
B:~/foo.git$ git commit -a
B:~/foo.git$ logout
A:~/foo.git$ git pull ssh://B/home/user/foo.git
A:~/foo.git$ git push ssh://B/home/user/foo.git master
(before being able to do that, I had to change git config on B and add a post-receive hook as described in the answer to this stackoverflow question)
My questions:
1) is the above correct?
2) is there a simpler way of achieving the same purpose?
|
Your post-receive hook has some pretty dire caveats IMO!
I have a similar setup, but server B has two copies of the repo. One is a bare repo and used as the default remote ("origin") for both. Then I don't have to supply arguments to "git push" and "git pull". That last is the only simplification I have over the commands you're mentioning. (And in my case B is a server; I have an ARM box I can just leave on).
If you "don't really use Git", it's not necessarily the best idea. Git was designed for power, and the UI is still not as consistent as other DVCS's. Simpler tools for this use might include
http://git-annex.branchable.com/assistant/ (new - I've not tried it)
http://www.cis.upenn.edu/~bcpierce/unison/ (old standby, works over ssh)
Dropbox (non-free and requires internet connection, but slick and will optimize transfers over the LAN as well)
Or there's Mercurial or even Darcs. I think either would avoid the issue that Git requires an extra bare repo or a worrying commit hook. Mercurial should be more user friendly than Git. Darcs has a different design to any other DVCS... so that might not be the best idea. Looking at the docs it seems Bazaar would be dubious for this case.
| How to use git for this particular purpose? |
1,597,610,216,000 |
I do not have root access on my Ubuntu but want to install git. I was following this tutorial but when running make or make install it says curl is not installed.
Can I use wget instead if this is a make config setting?
|
No, but you could build Git without the Curl dependency on libcurl. It will disable features. Remember that wget is just a binary, whereas Curl provides a shared library as well and that is used by Git. Three options here:
./configure Git with the option --without-curl. Docs say:
--with-curl support http(s):// transports (default is YES)
ARG can be also prefix for curl library and headers
You could install your own libcurl, configure it with a
non-standard --prefix= path and let Git link to that path instead
of a system-wide library path. It's is probably going to cost quite
some effort if you're not comfortable compiling manually.
It will be a lot easier however if you ask the administrator of that machine
to install the git package.
| make install - how to use wget, not curl |
1,597,610,216,000 |
I see that it takes a --format argument:
--format <format>
A string that interpolates %(fieldname) from a branch ref being shown and the object it points at. The format is the same as that of git-for-each-ref(1).
When I look at man git-for-each-ref I find
When unspecified, <format> defaults to %(objectname) SPC %(objecttype) TAB %(refname).
and at the bottom it has these examples:
--format='From: %(*authorname) %(*authoremail)
Subject: %(*subject)
Date: %(*authordate)
Ref: %(*refname)
%(*body)
' 'refs/tags'
--format="ref=%(refname)"
and then some more that I understand even less.
All I want is to change the shade of blue here. Help, please!
|
TLDR;
git config -g color.branch.upstream 'red bold'
Git Command:
git config color.branch.upstream '<fg-color> [<bg-color>] [<attribute>...]'
Git config file:
[color "branch"]
upstream = <fg-color> [<bg-color>] [<attribute>...]
Possible <fg-color> and <bg-color> values:
black blue cyan default green
magenta normal red white yellow
Optionally prefixed with bright for brighter shades of those colours or use #RRGGBB values.
Possible <attribute> values:
blink bold ul italic
reverse strike dim
Examples:
git config color.branch.upstream 'yellow red bold ul'
git config color.branch.upstream brightblue
git config color.branch.upstream '#c0c0ff'
See the git-config(1) man page for details and be aware that not every terminal supports everything. Also don't forget to use the --global flag to make the changes global :)
| How can I change the output colors of `git branch -vv` |
1,597,610,216,000 |
I want to create a bash function where you can do a sed find and replace while ignoring the files and folders in .gitignore. I also want to be able to add any git grep flags to the command. For example, for an exact match, I should be able to add -w.
This is what I have so far:
gs {
local grep_options=()
local search_pattern
local replacement
while [[ $1 =~ ^- ]]; do
grep_options+=("$1")
shift
done
search_pattern=$1
replacement=$2
git grep -l "${grep_options[@]}" "$search_pattern" | xargs sed -i "s/$search_pattern/$replacement/g"
}
gs pattern replacement will sucessfully do the search and replace. But gs -w pattern replacement won't do anything.
Why is this, and how to fix it?
|
You have a syntax error in function declaration.
Instead of
w { ... }
you need:
w() { ... }
Always pass your scripts to https://shellcheck.net before asking help:
$ shellcheck file
In file line 1:
gs {
^-- SC2148 (error): Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive.
^-- SC1083 (warning): This { is literal. Check expression (missing ;/\n?) or quote it.
In file line 2:
local grep_options=()
^---^ SC2168 (error): 'local' is only valid in functions.
In file line 3:
local search_pattern
^---^ SC2168 (error): 'local' is only valid in functions.
In file line 4:
local replacement
^---^ SC2168 (error): 'local' is only valid in functions.
In file line 15:
}
^-- SC1089 (error): Parsing stopped here. Is this keyword correctly matched up?
For more information:
https://www.shellcheck.net/wiki/SC2148 -- Tips depend on target shell and y...
https://www.shellcheck.net/wiki/SC2168 -- 'local' is only valid in functions.
https://www.shellcheck.net/wiki/SC1083 -- This { is literal. Check expressi...
| How to add an exact-match flag to the following git + sed function? |
1,597,610,216,000 |
git fetch --all --no-tags doesn't do what it says on the tin, and keeps re-fetching tags every time I run it. How do I actually fetch from all remotes without fetching tags?
To reproduce:
Fork this repo
Clone your fork
Add an upstream remote for [email protected]:cachix/install-nix-action.git
git fetch --all --no-tags
What should happen: No tags should be hurt by this transaction.
What actually happens: The remotes clobber each others' tags:
❯ git fetch --all --no-tags
Fetching origin
From github.com:example-user/install-nix-action
- [deleted] (none) -> [omitted]
[…]
Fetching upstream
From github.com:cachix/install-nix-action
* [new tag] [omitted] -> [omitted]
[…]
It even exhibits this behaviour when fetching only the default remote:
❯ git fetch --no-tags
From github.com:example-user/install-nix-action
- [deleted] (none) -> [omitted]
|
Based on my reading of the git-fetch documentation, --no-tags only tells git not to fetch any new tags from your remotes. Cleaning up local tags that no longer exist on the remotes you're pulling from is driven by a different setting, namely fetch.pruneTags. If the output of git config --list shows fetch.pruneTags=true, it means you've likely enabled this feature manually at some point. You should remove this setting to go back to the default behaviour of not pruning tags when fetching from remotes.
| How to fetch from Git remotes without tags? |
1,597,610,216,000 |
There's a lot of setup for this question:
I've got a host (rpi5.local) with 2 user accounts: pi and cake.
I wanted to explore git, and I created the cake account to "own" the "server/origin" repos. As user cake, in /home/cake, I created a folder (git-srv) with a sub-folder called projectA. I went through the process of initializing this repo using git init --bare.
Initially, I "populated" the projectA repo on the server from another host (rpi4b.local). I pushed some files in a folder called Aproject on the raspberrypi4b.local host to the projectA repo via SSH using this sequence:
$ hostname
rpi4b.local
$ pwd
/home/pi/Aproject
$ git push -u ssh://[email protected]/home/cake/git-srv/projectA.git
This worked fine.
As user pi, I cloned the projectA repo to a folder in /home/pi/XYZ. I made & commited some changes to one of the files in /home/pi/XYZ, and attempted to push those changes to the server as follows:
$ hostname
rpi5.local
$ pwd
/home/pi/XYZ
$ git push -u /home/cake/git-srv/projectA.git
I got an error from this effort:
...
error: remote unpack failed: unable to create temporary object directory
To /home/cake/git-srv/projectA.git
! [remote rejected] master -> master (unpacker error)
error: failed to push some refs to '/home/cake/projectA.git'
After a bit of research on this error, I concluded it was a permissions issue between pi and cake. I figured the solution would be to su cake as user pi, and so I did that, and tried the push again. And finally, my question:
$ whoami
cake
$ hostname
rpi5.local
$ pwd
/home/pi/XYZ
$ git push -u /home/cake/git-srv/projectA.git
fatal: failed to stat '/home/pi/motd.git': Permission denied
What does failed to stat mean in this situation, and is there a straightforward work-around?
|
“Failed to stat” means that a call to stat returned an error, i.e. that the user running git doesn’t have permissions to obtain information on /home/pi/motd.git. That’s presumably because the cake user doesn’t have access to /home/pi.
Instead of trying to find the right set of permissions in this case, I think the most straightforward approach is to use SSH again (even though it’s the same system): git push ssh://git@localhost:/home/cake/git-srv/projectA.git or git push ssh://cake@localhost:git-srv/projectA.git.
| After `su user`, getting `fatal: failed to stat : Permission denied` with `git push` |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.