Copying updated files

I have a directory with source code and want to figure out the files whose content has changed.

Suppose I have two version of development work called hstmy.1.0 and hstmy.1.7. Directory structure are basically the same. However there may be additional files and directories, whose contents have changed (new source codes, bug fixes, etc).

 hstmy.1.0
    baseLib
    bin
       awk
       ksh
       prog
       tcsh
    fortran
    others
    scripts
    source

 hstmy.1.7
    baseLib
    bin
       awk
       ksh
       prog
       tcsh
    fortran
    others
    scripts
    source

I want to know which files differ and copy them to a temporary directory

As example, hstmy.1.0 is as shown below

 hstmy.1.0
     baseLib
       common.hh
       Complex.hh
       CSpInterp1D.hh
       CSpInterp2D.hh
       Darwin.hh
       DFT1.hh
       DFT2.hh
       dftUtils.hh
       DynBaseObj.hh
       FPnInterp1D.hh
       FPnInterp2D.hh
       GenFunc.hh
       Interp1D.hh
       Interp2D.hh
       invers.hh
       LinAlg.hh
       LinInterp1D.hh
       LinInterp2D.hh
       List.hh
       Matrix.hh
       ObjFunc.hh
       Optimize.hh
       ParseEl.hh
       Parsing.hh
       Poly1.hh
       Poly2.hh
       Random.hh
       Simplex.hh
       Stack.hh
       String.hh
       Tensor2.hh
       Tree.hh
       Vect2.hh
       Vector.hh
       Verbose.hh
    bin
       awk
          addNoise-dat.awk
          addNoise-dat.awk.pdf
          addNoise-dat.awk.ps
          addNoise-xt.awk
          awkNotes.txt
          change-log.awk
          change-text.awk
          checkSRDist.awk
          checkSRDist-dat.awk
          checkSRDist-ry.awk
          checkSRDist-xt.awk
          createAnmly-zc.awk
          example.awk
          jcd2zc.awk
          log2cmd.awk
          modeli2cmod.awk
          n02-z30.ry
          n02-z30.ry.bck
          n02-z30.xt.bck
          removeSndSp-zc.awk
          removeSRDist-dat.awk
          removeSRDist-ry.awk
          removeSRDist-xt.awk
          result
          test.ry
          test.ry.bck
          test.txt
          test.txt.bck
          test.xt
          test.xt.bck
          timeDistAbs.txt
          timeDistAbs.txt.bck
          timeDistAbs.txt.bck.bck
          xt2dat.awk
          xt2dat-v2.awk
          zc2cmd.awk
          zc2zfc.awk
          zp2pmd.awk
       ksh
          check-srdist.ksh
          comp-xt.ksh
          convert-zfc-fcmod.ksh
          cr-data-tinv.ksh
          crmisfit.ksh
          crmodel.ksh
          hseis-processing.ksh
          pl-jcd-zc.ksh
          plmisfit.ksh
          plmodel.ksh
          plry.ksh
          plryxt.ksh
          plxy.ksh
          raytrac.ksh
          rmsrdist.ksh
          tdarwin.ksh
          tsimplex.ksh
       prog
          getmisf
          getpdf
          getvel
          linint
          raytrac
          tdarwin
          tracepdf
          tsimplex
       tcsh
           browseDir.tcsh
           checkSRDist.tcsh
           create-data-tinv.tcsh
           createDocs.tcsh
           createMisfit.tcsh
           createModel.tcsh
           createTrvt.tcsh
           file0p12-22344.txt
           file0p12-23234.txt
           file0p12-77364.txt
           file0p12.txt
           file0p12.txt.bck
           hseis-processing.tcsh
           plotMisfit.tcsh
           plotModel.tcsh
           plotryxt.tcsh
           plotxy.tcsh
           printTable.tcsh
           raytrac.tcsh
           removeFiles.tcsh
           removeRays.tcsh
           removeSRDist.tcsh
           removeText.tcsh
           removeTrvt.tcsh
           renameFiles.tcsh
           renameFiles-tcsh-to-csh.run
           replaceText.tcsh
           sortList.tcsh
           tcshrc.csh
           tdarwin.tcsh
           test.tcsh
           tsimplex.tcsh
           zfc2fcmod.tcsh
    fortran
       generate_rgaussian
       generate_rgaussian.f90
       generate_rgaussian.o
       hseistools.mod
       linint
       linint.f90
       linint.o
       rgaussian.f90
       rgaussian.o
       split_files_tt.f
       tt_resid.f
    Makefile
    Makefile.bck
    Makefilediag
    Makefile.old
    others
       asac2xy.cc
       asacdump.cc
       convtv.cc
       cwt.cc
       fourier.cc
       pp2sac.cc
       sac.h
       segy.h
       sucrpi.cc
       sufppk.cc
    source
        CSpLay.hh
        ElMap.hh
        FPnLay.hh
        GetMisf.cc
        GetPDF.cc
        GetVel.cc
        Layer.hh
        LayInt.hh
        LayMod.hh
        LinLay.hh
        Map.hh
        ModMisfit.hh
        RayField.hh
        Ray.hh
        RayTrac.cc
        Rdt.cc
        Source.hh
        Surface.cc
        Tdarwin.cc
        Tomog.hh
        TraceMis.cc
        TracePDF.cc
        Tsimplex.cc
        VelMod.hh

Hi kristinu,

Some questions:

  1. Omit files that exist in one branch but not in the other one?
  2. Compare both text and binary files?
  3. When found files that differ: copy both or one of them? and if that case, from which branch?
  4. Temporary dir will be plain? I mean, if found a file that differ inside two subdirectories, the script will have to create those subdirectories in the temporary dir or could be enough to copy the file without the tree structure?
  5. Why don't you use a source control system for the job?

There might be a better way to use rsync for this, but this ought to work unless you've been putting spaces in filenames:

rsync -r --list-only a b | # Find changes and list them
        awk '/^[^d]/ { print $5 }' | # Get only filenames
        xargs tar -cf - | # Bundle them up
        tar -C /path/to/destination -xf - # Extract elsewhere

I only care about source code changes (.hh, .cc, .awk, .tcsh, .ksh, .f, .F)

I want to just transfer the files without the tree structure to a folder, let's call it updatedcode. Will transfer only from
hstmy.1.7 the files that differ from hstmy.1.0

Yes, my intention is to use svn, but I am only starting on it. In the meantime I have to continue working.

---------- Post updated at 07:31 PM ---------- Previous update was at 07:23 PM ----------

There are no spaces in file names. I am working from home and work. I just want to transfer the updated files so I can have a look at the work done on the latest version.

I created source1 and source2. They are identical to directory source. I made changes to source2/TracePDF.cc.

However when I did

rsync -r --list-only source source2

I got

drwxr-xr-x        4096 2012/03/09 22:38:03 source
-rw-r--r--       12869 2012/02/08 13:58:30 source/CSpLay.hh
-rw-r--r--        4737 2012/02/08 11:28:26 source/ElMap.hh
-rw-r--r--       18955 2012/02/08 13:58:30 source/FPnLay.hh
-rw-r--r--        4034 2012/02/08 11:29:13 source/GetMisf.cc
-rw-r--r--        4144 2012/02/08 11:29:48 source/GetPDF.cc
-rw-r--r--        7442 2012/02/08 11:30:24 source/GetVel.cc
-rw-r--r--        6172 2012/02/08 13:58:27 source/LayInt.hh
-rw-r--r--        8250 2012/02/08 13:58:21 source/LayMod.hh
-rw-r--r--       24893 2012/02/08 13:58:26 source/Layer.hh
-rw-r--r--       12864 2012/02/08 13:58:22 source/LinLay.hh
-rw-r--r--       18886 2012/02/08 13:58:22 source/Map.hh
-rw-r--r--       23943 2012/02/08 13:58:23 source/ModMisfit.hh
-rw-r--r--       24137 2012/02/08 13:58:23 source/Ray.hh
-rw-r--r--       25086 2012/02/08 13:58:23 source/RayField.hh
-rw-r--r--       23521 2012/03/07 23:03:04 source/RayTrac.cc
-rw-r--r--        8052 2012/02/08 11:40:36 source/Rdt.cc
-rw-r--r--       10668 2012/02/08 13:58:18 source/Source.hh
-rw-r--r--        2582 2012/02/08 11:41:42 source/Surface.cc
-rw-r--r--       14682 2012/02/07 18:51:24 source/Tdarwin.cc
-rw-r--r--       19959 2012/02/08 13:58:18 source/Tomog.hh
-rw-r--r--        6434 2012/02/08 11:42:53 source/TraceMis.cc
-rw-r--r--        6617 2012/02/08 11:43:23 source/TracePDF.cc
-rw-r--r--       11190 2012/02/08 11:04:55 source/Tsimplex.cc
-rw-r--r--       24784 2012/02/08 13:58:14 source/VelMod.hh

rather than just

source2/TracePDF.cc

Yes, that's what all the awk nonsense is for, to get the proper filename out of it.

It may also be expecting source/* in the destination, as well as the source, in which case a symbolic link would fix it.

I tried it but it saved all the files in the directory test rather than just the one file
source2/TracePDF.cc