I have locally remove file from location using rm -rf . when I am trying p4 sync filename But I am not getting file name and getting message that file is update. I used to run similar command in cvs for getting file cvs update filename.
See the following: http://www.perforce.com/perforce/r12.1/manuals/cmdref/sync.html.
The relevant parts are as follows.
Syntax
p4 [g-opts] sync [-f] [-L] [-k] [-n] [-q] [-m max] [file[revRange]...]
p4 [g-opts] sync [-L] [-n] [-q] [-s] [-m max] [file[revRange]...]
p4 [g-opts] sync [-L] [-n] [-p] [-q] [-m max] [file[revRange]...]
The flag you want is as follows.
-f
Force the sync. Perforce performs the sync even if the client
workspace already has the file at the specified revision. If
the file is writable, it is overwritten.
This flag does not affect open files, but it does override the
noclobber client option.
Related
I get a changelist number and I am able to add the files to the changelist
>>> createdCLNumber
'1157545'
>>> p4.run_add("-c", createdCLNumber, "/Users/ciasto/ciasto_piekarz/sandbox/main/upgrade_tools/upgrade_gitlab")
['//depot/td/main/bin/upgrade_gitlab#1 - currently opened for add']
but when I try to submit them I get the error.
>>> p4.run_submit(changeList)
P4.P4Exception: [P4#run] Errors during command execution( "p4 submit -i" )
[Error]: 'No files to submit.'
If you want to submit a numbered changelist (implied by the fact that you used p4 add -c CHANGELIST), do:
p4 submit -c CHANGELIST
See p4 help submit:
submit -- Submit open files to the depot
p4 submit [-Af -r -s -f option --noretransfer 0|1]
p4 submit [-Af -r -s -f option] file
p4 submit [-Af -r -f option] -d description
p4 submit [-Af -r -f option] -d description file
p4 submit [-Af -r -f option --noretransfer 0|1] -c changelist#
p4 submit -e shelvedChange#
p4 submit -i [-Af -r -s -f option]
--parallel=threads=N[,batch=N][,min=N]
If you only specify a single argument, it's interpreted as a file path:
p4 submit [options] file
To specify a changelist you want this form:
p4 submit [options] -c changelist#
I'm having problems feeding a large list of filenames into a command in (git for windows git, I think it's cygwin)bash shell.
This is the basic command that works fine with a small set of arguments: git filter-branch -f --tree-filter 'rm -rf file1 directory2 file3 file4' However, I have about 1500 filenames.
I've tried: git filter-branch -f --tree-filter 'rm -rf file1 directory2... all 1500 names here' but I get an error:
/mingw64/bin/git: Argument list too long
I've tried to use a for loop: git filter-branch -f --tree-filter 'for f in $(cat files.txt) ; do rm -fr "$f" ; done' and this runs through the loop with an error:
cat: files.txt: No such file or directory
FYI - the files.txt contents look like this:
./file1
./directory2
./file3
./file4
Then I tried: git filter-branch -f --tree-filter < cat files.txt and cat files.txt | git filter-branch -f --tree-filter but I get errors about the syntax not being correct - it shows the 'help' dialogue. eg:
usage: git filter-branch [--setup ] [--subdirectory-filter
] [--env-filter ]
[--tree-filter ] [--index-filter ]
[--parent-filter ] [--msg-filter ]
[--commit-filter ] [--tag-name-filter ]
[--original ]
[-d ] [-f | --force] [--state-branch ]
[--] [...]
Then I thought maybe I could just add the arguments into the file like this: git filter-branch -f
File:
--tree-filter './file1 ./directory2 ./file3 ./file4'
But I get the 'help' dialogue again.
I'm sure there is a way to do this, but my unix-fu is too weak. Please help!
In response to #dash-o:
I tried this, but am getting an error:
C:/Program Files/Git/mingw64/libexec/git-core\git-filter-branch: eval:
line 414: unexpected EOF while looking for matching `'' C:/Program
Files/Git/mingw64/libexec/git-core\git-filter-branch: eval: line 415:
syntax error: unexpected end of file
The files.txt lists the files one per line. However, the rm -rf requires them to be on a single line and space-delimited.
I tried to put the files names on a single line, but I get a different error:
C:/Program Files/Git/mingw64/libexec/git-core\git-filter-branch: line
414: rm -rf .vs ./file1 ./directory2: command not found tree filter
failed: 'rm -rf ./file1 ./directory2'
Maybe the single quotes are being escaped and are not wrapped around the rm command?
Give this a try, just make sure you're in the path where files.txt is located to avoid the "No such file or directory" error :
for f in $(cat files.txt); do git filter-branch -f --tree-filter 'rm -rf '"$f"'' ; done
For cases of larger number of files, it might be time consuming to iterate over each file individually. For those cases, consider using xargs ability to batch arguments together (based on max number of argument, max command line size, etc).
xargs -L50 < files.txt | xargs -I# git filter-branch -f --tree-filter "'rm -rf #'"
The first xargs is used purely to arrange block arguments, 50 files each. This can be customized to include a line size limit, if needed.
The second xargs will execute git filter for each 50 arguments. You might need to work on the quoting, as I do not have the ability to test the command with git on windows).
I am trying to execute the scp command in such a way that it can copy .csv files from source to sink, except a few specific CSV file.
For example in the source folder I am having four files:
file1.csv, file2.csv, file3.csv, file4.csv
Out of those four files, I want to copy all files, except file4.csv, to the sink location.
When I was using the below scp command:
scp /tmp/source/*.csv /tmp/sink/
It would copy all the four CSV files to the sink location.
How can I achieve the same by using the scp command or through writing a shell script?
You can use rsync with the --exclude switch, e.g.
rsync /tmp/source/*.csv /tmp/sink/ --exclude file4.csv
Bash has an extended globbing feature which allows for this. On many installations, you have to separately enable this feature with
shopt -e extglob
With that in place, you can
scp tmp/source/(!fnord*).csv /tmp/sink/
to copy all *.csv files except fnord.csv.
This is a shell feature; the shell will expand the glob to a list of matching files - scp will have no idea how that argument list was generated.
As mentioned in your comment, rsync is not an option for you. The solution presented by tripleee works only if the source is on the client side. Here I present a solution using ssh and tar. tar does have the --exclude flag, which allows us to exclude patterns:
from server to client:
$ ssh user#server 'tar -cf - --exclude "file4.csv" /path/to/dir/*csv' \
| tar -xf - --transform='s#.*/##' -C /path/to/destination
This essentially creates a tar-ball which is send over /dev/stdout which we pipe into a tar extract. To mimick scp we need to remove the full path using --transform (See U&L). Optionally you can add the destination directory.
from client to server:
We do essentially the same, but reverse the roles:
$ tar -cf - --exclude "file4.csv" /path/to/dir/*csv \
| ssh user#server 'tar -xf - --transform="s#.*/##" -C /path/to/destination'
You could use a bash array to collect your larger set, then remove the items you don't want. For example:
files=( /tmp/src/*.csv )
for i in "${!files[#]}"; do
[[ ${files[$i]} = *file4.csv ]] && unset files[$i]
done
scp "${files[#]}" host:/tmp/sink/
Note that our for loop steps through array indices rather than values, so that we'll have the right input for the unset command if we need it.
I have a bash script used for copy some files from different directories in remote host. All of them have the same parent. So i put them into list:
LIST=\{ADIR, BDIR, CDIR\}
and i use the scp command
sshpass -p $2 scp -o LogLevel=debug -r $1#192.168.121.1$/PATH/$LIST/*.txt /home/test/test
that command makes me able to copy all of .txt files from ADIR, BDIR, CDIR to my test directory. Is there any option which can put all of .txt files in appropriate directory like /home/test/test/ADIR or /home/test/test/BDIR ... ?
Have you considered using rsync?
You could try something along these lines:
# Rsync Options
# -a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)
# -D same as --devices --specials
# -g, --group preserve group
# -l, --links copy symlinks as symlinks
# -o, --owner preserve owner (super-user only)
# -O, --omit-dir-times omit directories from --times
# -p, --perms preserve permissions
# -r, --recursive recurse into directories
# -t, --times preserve modification times
# -u, --update skip files that are newer on the receiver
# -v, --verbose increase verbosity
# -z, --compress compress file data during the transfer
for DIR in 'ADIR' 'BDIR' 'CDIR'
do
rsync -zavu --rsh="ssh -l {username}" 192.168.121.1:/$PATH/$DIR /home/test/test/
done
Finally my working code:
SOURCE='/usr/.../'
DEST='/home/test/test'
DIRS_EXCLUDED='test/ADIR test/BDIR'
EXTENSIONS_EXCLUDED='*.NTX *.EXE'
EXCLUDED_STRING=''
for DIR in $DIRS_EXCLUDED
do
EXCLUDED_STRING=$EXCLUDED_STRING'--exclude '"$DIR"' '
done
for EXTENSION in $EXTENSIONS_EXCLUDED
do
EXCLUDED_STRING=$EXCLUDED_STRING'--exclude '"$EXTENSION"' '
done
rsync -zavu $EXCLUDED_STRING --rsh="sshpass -p $2 ssh -l $1" 192.168.xxx.xxx:$SOURCE $DEST
I found this here but is seemed a commandline option and for some reason p4 grep did not give me results. It gave errors like "must refer to client".
So i am asking, does the P4 visual client(I have version 2012 Sep-21) have any provision to search depot files for certain content entered as keyword(s)?
This is what I did to use p4 grep command:
cd
p4 grep -i -n -e dmc ./
this gave error:
./ - file(s) not in client view.
So then tried doing switch command to change to that client/workspace(they are synonyms in Perforce):
p4 client -s MyClientName
It gave error saying:
Usage: client -s [ -f ] -t template | -S stream [ clientname ]
Then even tried further but could not use the -S -t option.
What is the command to switch a client which would resolve the error message "./ - file(s) not in client view."?
Well finally after lot of trials and errors (There is not much discussion about this online) I got the p4 grep command to work successfully.
cd to your
grep -i -n -F -e "class" //depot/folder1/folder2/code/*
The key is using the Perforce folder notation //depot/...
You can use any option of the grep command mentioned in its help.
One can even use regular expressions as patterns/keyword.
Well done your's truly.
No, p4v does not have the ability to search the content of files, you will need to use
"p4 grep" to do that.