Git: change timestamp after clicking

How to edit a commit mark after (randomly) by pushing it to a remote repository?

I changed my system clock to check the behavior in my application and forgot to return it back to git add -u . and git push . Now my GitHub repository shows several files that were edited "in a month."

I went for advice here - in particular, OP comments that recommend git push --force , but unfortunately the editing dates remain unchanged.

+6
source share
2 answers

Well, this article is about modifying a commit message, and then pushing the change forcefully. But here in this case, you first need to fix the commit mark before doing git push --force .

Read this article to find out how to fix the timestamp: How do I change the timestamp of an old commit in Git?

And then force click.

(Btw, on github, it may take several updates before you see the change. Also, I suppose you know that you are breaking the story, and if someone else cloned the repos, you have broken them, etc. etc. .d., right? good!)

+4
source

You can try the --date version of git commit , as described in this post by Alan Kelder :

Change / Reset timestamp for an already committed change

The above is great for incomplete changes, but what if you made changes and would like to change the AuthorDate time? Again, git makes this easy for a final commit:

 $ git commit --amend --date='<see documentation for formats>' -C HEAD 

Change / Reset timestamps for several changes already committed

But what if you need to return a few commits? I ran into this situation and used the following Bash script to reset AuthorDate time, here is what it does.

For a list of files, it will receive a hash of the last commit for each file, get the last modified date of the file, and then reset the author’s timestamp for the actual modified date of the file. Be sure to run it from the top level of the working tree (git will complain if you don't).

 files=" foo.txt bar.txt " for file in $files; do dir=""; commit=""; date=""; dir=$(dirname $(find -name $file)) commit=$(git --no-pager log -1 --pretty=%H -- path "$dir/$file") date="$(stat -c %y $dir/$file)" if [ -z "$commit" ] || [ -z "$date" ]; then echo "ERROR: required var \$commit or \$date is empty" else echo "INFO: resetting authorship date of commit '$commit' for file '$dir/$file' to '$date'" git filter-branch --env-filter \ "if test \$GIT_COMMIT = '$commit'; then export GIT_AUTHOR_DATE GIT_AUTHOR_DATE='$date' fi" && rm -fr "$(git rev-parse --git-dir)/refs/original/" fi echo done 

You can use the above script to reset both AuthorDate and CommitDate (just add GIT_COMMITTER_DATE to the code above using the example from the link below).
Although the CommitDate change for shared repositories seems messy, as you might confuse others.

+5
source

Source: https://habr.com/ru/post/950782/


All Articles