Script needed; git mavens can you help?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Script needed; git mavens can you help?

Eliot Miranda-2
 
Hi git mavens,

    I've used a script called svnrevert in the svn version that reverts any changed file in its argument(s), which may be directories, /and/ sets the modification date to the date at which the file was last checked in. I'd like the same functionality in git.  Her'es the subversion version:

#!/bin/bash
# Revert file(s) or all modified files in a directory
# and touch them back to the checkin date
for f in "$@"
do
if [ -d "$f" ]; then
$0 `svn st "$f" | grep "^M" | sed 's/^M *//'`
else
if svn revert "$f"; then
changed="`svn info \"$f\" | grep 'Last Changed Date:' | sed 's/ *(.*//'`"
touch -t "`date -j -f 'Last Changed Date: %Y-%m-%d %H:%M:%S %z' \"$changed\" '+%Y%m%d%H%M.%S'`" "$f"
fi
fi
done

_,,,^..^,,,_
best, Eliot
Reply | Threaded
Open this post in threaded view
|

Re: Script needed; git mavens can you help?

Tobias Pape


On 20.06.2016, at 22:40, Eliot Miranda <[hidden email]> wrote:

> Hi git mavens,
>
>     I've used a script called svnrevert in the svn version that reverts any changed file in its argument(s), which may be directories, /and/ sets the modification date to the date at which the file was last checked in. I'd like the same functionality in git.  Her'es the subversion version:

without the modification-date requirement

        git checkout -- ....

does what you want (given you have NOT staged/git-added it before).
I'm curious, what's important about the last commit date?

Best regards
        -Tobias


>
> #!/bin/bash
> # Revert file(s) or all modified files in a directory
> # and touch them back to the checkin date
> for f in "$@"
> do
> if [ -d "$f" ]; then
> $0 `svn st "$f" | grep "^M" | sed 's/^M *//'`
> else
> if svn revert "$f"; then
> changed="`svn info \"$f\" | grep 'Last Changed Date:' | sed 's/ *(.*//'`"
> touch -t "`date -j -f 'Last Changed Date: %Y-%m-%d %H:%M:%S %z' \"$changed\" '+%Y%m%d%H%M.%S'`" "$f"
> fi
> fi
> done
>
> _,,,^..^,,,_
> best, Eliot


Reply | Threaded
Open this post in threaded view
|

Re: Script needed; git mavens can you help?

Damien Pollet
In reply to this post by Eliot Miranda-2
 
To complete Tobias's answer, git checkout HEAD -- <files> will restore files from the most recent commit even if changes were staged.

In what situation do you use that script?

People on stack overflow seem to have pretty polarized opinions about fiddling with timestamps… one of the answers has something close, but there might be a simpler way…



On 20 June 2016 at 22:40, Eliot Miranda <[hidden email]> wrote:
 
Hi git mavens,

    I've used a script called svnrevert in the svn version that reverts any changed file in its argument(s), which may be directories, /and/ sets the modification date to the date at which the file was last checked in. I'd like the same functionality in git.  Her'es the subversion version:

#!/bin/bash
# Revert file(s) or all modified files in a directory
# and touch them back to the checkin date
for f in "$@"
do
if [ -d "$f" ]; then
$0 `svn st "$f" | grep "^M" | sed 's/^M *//'`
else
if svn revert "$f"; then
changed="`svn info \"$f\" | grep 'Last Changed Date:' | sed 's/ *(.*//'`"
touch -t "`date -j -f 'Last Changed Date: %Y-%m-%d %H:%M:%S %z' \"$changed\" '+%Y%m%d%H%M.%S'`" "$f"
fi
fi
done

_,,,^..^,,,_
best, Eliot




--
Damien Pollet
type less, do more [ | ] http://people.untyped.org/damien.pollet
Reply | Threaded
Open this post in threaded view
|

Re: Script needed; git mavens can you help?

timfelgentreff
 

Hi Eliot,

When I did the migration I made a gitrevert script. It is in the scripts dir.

Best,
Tim

Am 20.06.2016 23:12 schrieb "Damien Pollet" <[hidden email]>:
 
To complete Tobias's answer, git checkout HEAD -- <files> will restore files from the most recent commit even if changes were staged.

In what situation do you use that script?

People on stack overflow seem to have pretty polarized opinions about fiddling with timestamps… one of the answers has something close, but there might be a simpler way…



On 20 June 2016 at 22:40, Eliot Miranda <[hidden email]> wrote:
 
Hi git mavens,

    I've used a script called svnrevert in the svn version that reverts any changed file in its argument(s), which may be directories, /and/ sets the modification date to the date at which the file was last checked in. I'd like the same functionality in git.  Her'es the subversion version:

#!/bin/bash
# Revert file(s) or all modified files in a directory
# and touch them back to the checkin date
for f in "$@"
do
if [ -d "$f" ]; then
$0 `svn st "$f" | grep "^M" | sed 's/^M *//'`
else
if svn revert "$f"; then
changed="`svn info \"$f\" | grep 'Last Changed Date:' | sed 's/ *(.*//'`"
touch -t "`date -j -f 'Last Changed Date: %Y-%m-%d %H:%M:%S %z' \"$changed\" '+%Y%m%d%H%M.%S'`" "$f"
fi
fi
done

_,,,^..^,,,_
best, Eliot




--
Damien Pollet
type less, do more [ | ] http://people.untyped.org/damien.pollet

Reply | Threaded
Open this post in threaded view
|

Re: Script needed; git mavens can you help?

Eliot Miranda-2
 


On Mon, Jun 20, 2016 at 10:39 PM, Tim Felgentreff <[hidden email]> wrote:
 

Hi Eliot,

When I did the migration I made a gitrevert script. It is in the scripts dir.


Thanks Tim.  Just an FYI for Mac users, the script presumes an up-to-date git, but Mac OS X yosemite only ships with 2.4.9.  The upgrade is easy; I'm currently using 2.10.0.

Best,
Tim

Am 20.06.2016 23:12 schrieb "Damien Pollet" <[hidden email]>:
 
To complete Tobias's answer, git checkout HEAD -- <files> will restore files from the most recent commit even if changes were staged.

In what situation do you use that script?

People on stack overflow seem to have pretty polarized opinions about fiddling with timestamps… one of the answers has something close, but there might be a simpler way…



On 20 June 2016 at 22:40, Eliot Miranda <[hidden email]> wrote:
 
Hi git mavens,

    I've used a script called svnrevert in the svn version that reverts any changed file in its argument(s), which may be directories, /and/ sets the modification date to the date at which the file was last checked in. I'd like the same functionality in git.  Her'es the subversion version:

#!/bin/bash
# Revert file(s) or all modified files in a directory
# and touch them back to the checkin date
for f in "$@"
do
if [ -d "$f" ]; then
$0 `svn st "$f" | grep "^M" | sed 's/^M *//'`
else
if svn revert "$f"; then
changed="`svn info \"$f\" | grep 'Last Changed Date:' | sed 's/ *(.*//'`"
touch -t "`date -j -f 'Last Changed Date: %Y-%m-%d %H:%M:%S %z' \"$changed\" '+%Y%m%d%H%M.%S'`" "$f"
fi
fi
done

_,,,^..^,,,_
best, Eliot




--
Damien Pollet
type less, do more [ | ] http://people.untyped.org/damien.pollet





--
_,,,^..^,,,_
best, Eliot
Reply | Threaded
Open this post in threaded view
|

Re: Script needed; git mavens can you help?

Nicolas Cellier
 


2016-09-27 21:24 GMT+02:00 Eliot Miranda <[hidden email]>:
 


On Mon, Jun 20, 2016 at 10:39 PM, Tim Felgentreff <[hidden email]> wrote:
 

Hi Eliot,

When I did the migration I made a gitrevert script. It is in the scripts dir.


Thanks Tim.  Just an FYI for Mac users, the script presumes an up-to-date git, but Mac OS X yosemite only ships with 2.4.9.  The upgrade is easy; I'm currently using 2.10.0.

Then apple unecessarily exposes its users to vulnerabilities, so they are urged to upgrade.
http://www.theregister.co.uk/2016/03/16/git_server_client_patch_now/ (my son's discovery)
 

Best,
Tim

Am 20.06.2016 23:12 schrieb "Damien Pollet" <[hidden email]>:
 
To complete Tobias's answer, git checkout HEAD -- <files> will restore files from the most recent commit even if changes were staged.

In what situation do you use that script?

People on stack overflow seem to have pretty polarized opinions about fiddling with timestamps… one of the answers has something close, but there might be a simpler way…



On 20 June 2016 at 22:40, Eliot Miranda <[hidden email]> wrote:
 
Hi git mavens,

    I've used a script called svnrevert in the svn version that reverts any changed file in its argument(s), which may be directories, /and/ sets the modification date to the date at which the file was last checked in. I'd like the same functionality in git.  Her'es the subversion version:

#!/bin/bash
# Revert file(s) or all modified files in a directory
# and touch them back to the checkin date
for f in "$@"
do
if [ -d "$f" ]; then
$0 `svn st "$f" | grep "^M" | sed 's/^M *//'`
else
if svn revert "$f"; then
changed="`svn info \"$f\" | grep 'Last Changed Date:' | sed 's/ *(.*//'`"
touch -t "`date -j -f 'Last Changed Date: %Y-%m-%d %H:%M:%S %z' \"$changed\" '+%Y%m%d%H%M.%S'`" "$f"
fi
fi
done

_,,,^..^,,,_
best, Eliot




--
Damien Pollet
type less, do more [ | ] http://people.untyped.org/damien.pollet





--
_,,,^..^,,,_
best, Eliot