Normally I use two PCs, say: PC1 and PC2.
On both of them I'm using CygWin on Windows 10.
They had the same configuration.
On PC1 I was trying to do some adjustments on how to display the date and time when doing:
$ git log
I was trying multiple bash and git commands.
In the past and also currently on PC2 when I do:
$ date
I get the following:
Tue Sep 25 16:17:34 CDT 2018
but on PC1 (the wrong one), with the same command, I get:
Tue, Sep 25, 2018 16:17:34
where you can see that the TimeZone indicator is not showing up.
Also, now on PC1, when I do a commit and then list the history with: $ git log, dates are like:
Date: Tue Sep 25 22:58:42 2018 +0100
where it should be:
Date: Tue Sep 25 16:58:42 2018 -0500
because my current timezone is: CDT (America/Chicago) (-05:00)
Any idea on how to solve this?
Thanks!
[EDIT 1]
Responding to suggestion from #Johan below where he said:
--- begin of comment ---
You need to set the git log --date to local.
git config --global log.date local
--- end of comment ---
I just tried that and now the date that shows up on my last commit doesn't have the TimeZone indicator. Using the same time reference as before it would be:
Date: Tue Sep 25 22:58:42 2018
I need to get the TimeZone indicator on the commit list.
[EDIT 2]
Responding to suggestion from #Johan below where he said:
--- begin of comment ---
You need to set the git log --date to default.
git config --global log.date default
--- end of comment ---
I just tried that and now and I get again:
Date: Tue Sep 25 22:58:42 2018 +0100
even trying new commits.
You need to set the git log --date to default.
git config --global log.date default
Source: git: timezone and timestamp format
I don’t think this will address the root issue on your system, but it will certainly help with git’s commit dates. Git uses an environment variable called TZ to set the timezone (for any command, not only commit), so you can set an alias for it in your shell:
alias git='TZ=CDT /usr/bin/git'
Check if the issue persists when:
using a regular CMD
setting a simplified PATH
That is:
set PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\
set GH=C:\path\to\git
set PATH=%GH%\bin;%GH%\usr\bin;%GH%\mingw64\bin;%PATH%
Note that with that setup, you benefit from 200+ Linux-like commands without even opening a bash (again, from a regular CMD session): you can type ls -alrth or grep or ... (directly from the CMD, no bash)
Since the date used in a commit is directly from the system, if time /T returns the proper hour (including DST), you won't have any issue with a git log date.
Related
I am using a .bat file in windows 10 to push changes to an external repo, I have the following code
#!/bin/bash
cd C:\path\to\my\repo
set timestamp=$(date +"%D %T")
git add .
git commit -m "Backup at: `%timestamp%`"
git push origin master
git pull origin master
What I want to do is have the commit message be "Backup at: date" but it just makes it "Backup at: `$(date +T)\`"
Is there a way I can fix this to make it the date?
You could write your script as a regular bash shell script since Windows executes .sh files using Git Bash.
So write it like this:
Example: myBackup.sh
#!/bin/bash
cd /c/path/to/repo
timestamp=$(date +%c)
git add .
git commit -m "Backup at: $timestamp"
git push origin master
echo Press Enter...
read
$(date +%c) Will give you the locale date and time (e.g., Sun, Mar 15, 2020 12:01:53 AM) Use date --help to see full options. no need for set
Use variable like $timestamp not %timestamp% and without the backticks (``)
Use Forward slash / not Backslash \ Backslash works on Windows.
I made ipkg upgrade on my old tomatousb, which it seems resulted at least in a broken ls command:
[root#tomatousb root]$ /bin/ls /
/
[root#tomatousb root]$ ls /bin
/bin
however, the results are displayed in different colours.
There is also strange behaviour:
[root#tomatousb root]$ echo $PATH
echo $PATH
sh: echo: Permission denied
[root#tomatousb root]$ /bin/echo $PATH
/bin/echo $PATH
/opt/bin:/opt/sbin:/bin:/sbin:/usr/bin:/usr/sbin
I have no glue what's wrong to it.
The logs I see are as following:
/var/log/messages
Jan 1 04:00:11 tomatousb user.info kernel: ipt_recent v0.3.1: Stephen Frost <sfrost#snowman.net>. http://snowman.net/projects/ipt_recent/
Jan 31 23:10:21 tomatousb user.notice root: <<<< MPCSD: Config-files not found in /jffs/config/mpcs & /opt/etc/mpcs!!! Exit. >>>>
Jan 31 23:11:02 tomatousb cron.err crond[143]: time disparity of 25290430 minutes detected
Jan 31 23:37:26 tomatousb authpriv.info dropbear[505]: Child connection from *.*.*.*:*
So, basically, when I do SSH, I get to dropbear.
It seems that during the last ipkg upgrade I got new bash, tcpdump, and two more items, but I can't recall which exactly.. And I can't find the ipkg logfile...
Finally I bumped into my own old discussion when I had the same issue with the same box, and here's what was the reason:
[root#tomatousb mnt]$ cat /opt/etc/profile
#
# Bash initialization script
#
PS1="[\u#\h \W]$ "
PATH=/opt/sbin:/opt/bin:/sbin:/bin:/usr/sbin:/usr/bin
LD_LIBRARY_PATH=/opt/lib:${LD_LIBRARY_PATH}
export PS1 PATH LD_LIBRARY_PATH
[root#tomatousb mnt]$ rm /opt/etc/profile
Then I did reboot, and everything restored back to normal operation!
Do not know what exactly was in that profile file that ruined everything and caused 'memory exhausted' error when running vi.
I'm trying to get the log for a file with square brackets in its name. In case it matters: the OS is Windows and i'm using git bash.
If you create a file with [] in its name like [Start_here].bat then git log will not work.
I tried:
git log '[Start_here].bat'
git log \[Start_here\].bat
git log '\[Start_here\].bat'
git log -- '[Start_here].bat'
git log -- \[Start_here\].bat
git log -- '\[Start_here\].bat'
And none of them seemed to work. Either it did not display any commits or displayed a list of unrelated commits.
Does anybody have a solution that works?
Note:
git mv '[Start_here].bat' 'start_here.bat'
git log --follow start_here.bat
does show me a history in which the file was changed.
Edit:
Using the following script executed in a new repo I can see git log behaving correctly untill you add a submodule. Then it starts listing all the commits that changed a submodule too...
#!/usr/bin/env bash
set -x
rm -rf test-repo
rm -rf test-submodule
mkdir test-submodule
pushd test-submodule
git init
git config --local user.name tester1
git config --local user.email test#here.com
echo "a single line" > file.txt
git add file.txt
git commit -m "first commit"
popd
mkdir test-repo
pushd test-repo
git init
git config --local user.name tester1
git config --local user.email test#here.com
git branch -m master
echo "first line" > somefile.txt
git add somefile.txt
git commit -m "First line"
echo "another line" >> somefile.txt
git add somefile.txt
git commit -a -m "Second line"
echo "A line" > "[__Odd__].txt"
git add "[__Odd__].txt"
git commit -m "Adding odd file"
echo "third line" >> somefile.txt
git commit -a -m "Another bold statement."
echo "2nd line" >> "[__Odd__].txt"
echo "more" >> somefile.txt
git add "[__Odd__].txt" somefile.txt
git commit -m "changed both in master1"
git checkout -b new_branch
echo "2nd line" >> "[__Odd__].txt"
echo "more" >> somefile.txt
git add "[__Odd__].txt" somefile.txt
git commit -m "changed both in new_branch"
git checkout master
echo "2nd line" >> "[__Odd__].txt"
echo "more" >> somefile.txt
git add "[__Odd__].txt" somefile.txt
git commit -m "changed both in master"
git submodule add -- ../test-submodule module
git commit -m "Added submodule"
git log -- "[__Odd__].txt"
This outputs:
commit c3ebc7e0daf68543d761fc3b06c7ab35e014efaf (HEAD -> master)
Author: tester1 <test#here.com>
Date: Fri Nov 17 13:06:07 2017 +0100
Added submodule
commit 03a935df578a2eaf3f42789bd1e89e313224797a
Author: tester1 <test#here.com>
Date: Fri Nov 17 13:06:06 2017 +0100
changed both in master
commit d617db69dd9468e88587e2363050fdf57ac10756
Author: tester1 <test#here.com>
Date: Fri Nov 17 13:06:06 2017 +0100
changed both in master1
commit 88a07e5c887d63ead4e6cedd6349dfaf85ec1866
Author: tester1 <test#here.com>
Date: Fri Nov 17 13:06:05 2017 +0100
Adding odd file
Notice the top entry, it should not be here. It is related only to the submodule not to the file i want the log for.
git log -- somefile.txt does not output changes related to the submodules
In CMD, try:
git log -- "[__Odd__].txt"
or
git log -- ./"[__Odd__].txt"
Proof: https://imgur.com/7qqsVJ6
If everything fails, you can install WSL, and use git for tricky situations there.
Update 1 - From the comments:
you, sir, have found a bug in git for windows! I can reproduce your git log, and I can't reproduce it in WSL using linux's git, but can reproduce it using git.exe within WSL!
Filed a report: github.com/git-for-windows/git/issues/1371, let's see what comes of it
Update 2: This was a real bug in the code Git software, which has been fixed due to this question! How amazing 🎉 is that?!?!
Git on Windows comes in two flavors:
one using the Bash shell, and another using DOS.
The former is called Git Bash, the latter Git Cmd.
In Git Bash, git log '[foo]' should work.
In Git Cmd, git log "[foo]" should work (this also works in Git Bash btw).
In a DOS shell, you cannot use single-quotes to enclose strings that contain special characters.
(Special in the sense of "special to the shell".)
In Bash you can.
This is why, it looks like you are using Git Cmd.
Also keep in mind that auto-completion is your friend.
Both Git Bash and Git Cmd can auto-complete path names.
For example in Git Cmd if you start typing git log "[ and then press TAB,
it should give you some options to auto-complete.
If you start typing git log '[ and then press TAB,
it won't give you any options.
That's how you know the syntax is already wrong and you can stop typing and try another way.
I just tested, with Git 2.15 for Windows, the double-quotes.
It works with git bash:
vonc#VONCAVN7:/mnt/d/git/talks$ git log -- "[r].txt"
commit 7a698bf83cb55fa479200a3585b03ece1ee5db0a (HEAD -> 201710_docker)
Author: VonC <vonc#laposte.net>
Date: Mon Nov 13 20:33:04 2017 +0100
test
Or directly from a CMD shell session:
vonc#VONCAVN7 D:\git\talks
> git log -- "[r].txt"
commit 7a698bf83cb55fa479200a3585b03ece1ee5db0a (HEAD -> 201710_docker)
Author: VonC <vonc#laposte.net>
Date: Mon Nov 13 20:33:04 2017 +0100
test
To be sure you don't have any other program interfering with Git, try the same Git log after having set a simplified PATH.
root ~$ shutdown
-sh: shutdown: not found
root ~$ shutdown -h now
-sh: shutdown: not found
None of the commands are working . I think I need to link the command from scratch. Can anybody guide?
uname -a
gives
2.6.35.3 #49 PREEMPT Wed Jun 11 20:03:43 IST 2014 armv5tejl GNU/Linux
Try to call the command with complete path: /sbin/shutdown
moreover on most systems it is a root only command, so you should call it from root user (I am seeing the $ at the end of command prompt, so I am guessing you are not root)
Other commands you can try are presented here;
or you can use the init 0 command always as root user.
Writing the shutdown code is a last costly resort only if all the other alternatives fail.
I am in a running docker container with node and for some reason the timezones / the time of the host machine vs inside the docker container never line up:
root#foobar:~# node -e "console.log(new Date())"
>> Tue May 17 2016 15:12:43 GMT+0200 (CEST)
root#foobar:~# docker exec 9179105c0ff9 node -e "console.log(new Date())"
>> Tue May 17 2016 13:13:01 GMT+0000 (Europe)
root#foobar:~# cat /etc/timezone
>> Europe/Vienna
root#foobar:~# docker exec 9179105c0ff9 cat /etc/timezone
>> Europe/Vienna
So what I already did in my docker-start shell is script is the following:
docker run \
...
-v /etc/localtime:/etc/localtime:ro \
-v /etc/timezone:/etc/timezone:ro \
-e "TZ=Europe/Vienna" \
...
... but still, as you can see in the first codeblock, the time is still wrong! Any ideas on this? What am I missing?
(fyi: I am running a meteor app deployed via mupx)
UPDATE:
After running date on the host and inside the container, there again is a difference of 2hrs. so for some reason the docker container just does not "apply" my timezone and it seems like the problem is not JS/node related, since dateis just a simple unix system cmd ... what am I missing here?!
>> Tue May 17 2016 15:12:43 GMT+0200 (CEST)
and
>> Tue May 17 2016 13:13:01 GMT+0000 (Europe)
are approximately the same time(around 18sec difference, because you didn't ran the commands at the same time).
Take a closer look, it's around 3pm GMT+0200 and around 1pm GMT+0000.
This is just a difference in output format, but the time is the same.
If you execute .getTime() on the value of the new Date(), you will probably have the same values.
This is probably due to differences in default output format in different node.js versions.
I do it in this way:
args: ["-v /etc/timezone:/etc/timezone:ro","-v /etc/localtime:/usr/share/zoneinfo/Europe/Prague:ro", '-e TZ=Europe/Prague']
Need to install timedatectl
I was surprised to see the same problem when using new Date().toString() in a container. It always returns the string for GMT+000, and not for the server's time zone. There might be container-specific settings to change the time zone, but since I know my time zone - New York, I just used toLocaleString:
new Date().toLocaleString("en-US", {timeZone: "America/New_York"})