I need to rsync a git project folder and I'm using the follow rsync flags -r -a -v -u -W but when I run git status on the destination folder it does not match with git status on the source (I get modified/deleted files that were not actually touched).
Why is this happening? And how to make it work as intended?
From rsync manual:
-u, --update skip files that are newer on the receiver
So it may skip files...
Use git
Anyway, there is no need for rsync when you have the source dir versioned.
Clone the folder
cd /my/destination
git clone /my/source/repo
Sync the folder
cd /my/destination/repo
git fetch
The usual rsync command I use is
rsync --archive --delete --verbose src-dir/ dst-dir/
This makes dst-dir an exact mirror of src-dir. This will pick up everything, including your .git subdir and untracked files.
Related
I am trying to initialize a git repro on a samba mount with very limited permissions.
Trying to init I will receive:
$ git init .
error: chmod on /mnt/server/subfolder/.git/config.lock failed: Operation not permitted
fatal: could not set 'core.filemode' to 'false'
Which is surprising as filemode is already globally set to false
$ git config --get core.filemode
false
The Problem in general is that /mnt/server is a samba mount to a folder to which I have very limited access.
Also I am not able to change any permission for the /mnt/server mount as I am working on shared server with on which several users need the access to the /mnt/server mount.
So changing mounting permission like suggested here is not an option.
Also creating a symlink like suggested here does not work, as symlinks are not enabled on the samba drive.
So the question is how to prevent git from failing a chmod error or prevent it from doing chmod at all?
Is this possible?
Or how do I init a git in the environment?
A bit hacky solution is:
Init the an empty repro at destiantion with sufficient permission i.e. mktemp -d.
$ tempdir = $(mktemp -d)
$ git init $tempdir
Initialized empty Git repository in /tmp/tmp.pREa198fnx/.git/
Move the created .git folder to target destination.
$ mv $tempdir/.git /srv/server/sub/
mv: preserving times for './.git/branches': Operation not permitted
mv: preserving permissions for ‘./.git/branches’: Operation not permitted
mv: preserving times for './.git/hooks/applypatch-msg.sample': Operation not permitted
mv: preserving permissions for ‘./.git/hooks/applypatch-msg.sample’: Operation not permitted
mv: preserving times for './.git/hooks/commit-msg.sample': Operation not permitted
...
There will some error during moving but it won't stop mv from moving the files.
In the end the git works as expected:
$ echo "Foo" > bar.txt
$ git add bar.txt
$ git commit -m "Added Foobar"
[master (root-commit) e232039] bar.txt
1 file changed, 1 insertion(+)
create mode 100755 bar.txt
$ git status
On branch master
nothing to commit, working tree clean
branch and checkout seems to work to, didn't test push/pull.
Would still appreciate a cleaner solution.
I don't know if this question should be moved to ServerFault or it belongs here!
Working on a remote Unix server, I created a file file_x.php using FileZilla.
I'm using GIT on the terminal.
When I do git status, it shows me this :
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
some_other_file1.php
some_other_file2.php
file_x.php
^
|__ Note this weird blank space
The problem : I wanted to delete this file, I tried from FileZilla but this didn't work, it shows me there is no such file or directory ! But the file is always there!
So I tried :
rm -rf file_x.php # This didn't work
sudo rm -rf file_x.php # I'm not from the sudoers
git checkout file_x.php # This didn't do a thing !
git clear -f # This didn't do a thing !
git rm file_x.php
==> fatal: pathspec 'file_x.php' did not match any files
My question, what does this mean ? and how do I remove this file ?
You have to escape the space:
rm \ file_x.php
Is it possible to use the command git diff --no-index on two remote servers through ssh.
I want to use the output of the command git diff but on a non repository . Between two remote ssh directory .
I've never bridged a diff command across servers, but effectively...you'd just be using diff. git diff uses whatever system-specified diff tool you have available to compare different versions, and since --no-index would allow you to compare across non-versioned files, diff is your best bet.
You can try this:
# Get the working tree from repo 1:
git archive --format=zip --remote=ssh://<user>#<host>/repo1/<repo1 name> <tag or HEAD> > archive1.zip
# Get the working tree from repo 2:
git archive --format=zip --remote=ssh://<user>#<host>/repo2/<repo2 name> <tag or HEAD> > archive2.zip
mkdir tmpdir tmpdir2
(cd tmpdir; git init .)
# Unzip archive1 into tmpdir, make a temporary git repo out of it:
(cd tmpdir; unzip ../archive1.zip ; git add .; git commit -a -m "archive1")
# Move the .git directory to tmpdir2:
mv tmpdir/.git tmpdir2
# Unzip archive2 into tmpdir2, and compare:
(cd tmpdir2; unzip ../archive2.zip ; git diff ) > git-diff.txt
# Cleanup:
rm -rf tmpdir tmpdir2 archive1.zip archive2.zip
i am trying to find the name of git branch on remote server using a shell script. I put the following command in a script under the bin directory.
git symbolic-ref --short HEAD
When I execute the script using ssh from another machine
ssh -i keyfile.pem user#ipaddress 'bash -s' /path/to/the/script
I get an error
fatal: Not a git repository (or any of the parent directories): .git
Not sure where I am doing wrong. Any help would be appreciated.
Thanks.
Your call to git is using the wrong working directory (likely your home directory).
In your script, either cd to the path containing the git directory or specify the -C option with git:
git -C /path/to/git/checkout symbolic-ref --short HEAD
The -C option allows you to overwrite the working directory:
-C <path>
Run as if git was started in <path> instead of the current working directory. When
multiple -C options are given, each subsequent non-absolute -C <path> is interpreted
relative to the preceding -C <path>.
I've been trying to create a new alias that send files to staging area, and at the same time it commit with a message.
I've tried this:
git config --global alias.stagecomm '!git add -A && git commit -m $1'
When I try to run:
git stagecomm "Commit"
It says that it didn't match any files known to git.
Try with a sh: edit your git config --global --edit and type:
!sh -c 'git add -A && git commit -m $1'
Another option: define a script (even on Windows) without extension, called git-stagecomm
In it, put your commands:
git add -A
git commit -m $1
If that script is in your path, you will be able to call it with git stagecomm "mymessage"
Any script called git-xxx will be executed by the git bash, as git xxx.
No alias needed there.
That being said, you could also type (without alias)
git commit -am "My message"
See git commit man page.
-a
--all
Tell the command to automatically stage files that have been modified and deleted, but new files you have not told Git about are not affected.
That would not take new files though.