If x=$(git rev-list -1 "$GIT_COMMIT" -not '"$new_commit"') & parent-filter "sed -e s/$before_commit/$new_commit/g" \ New_commit=$(git rev-parse -verify HEAD)įile_blob=$(git rev-parse -verify HEAD:"$file_path") If you want the file to be added via a new commit that is to be inserted into the middle of your history, then you will need to generate the new commit prior to using git filter-branch and add -parent-filter to git filter-branch: file_path=path/to/file Git update-index -add -cacheinfo 100644 '"$file_blob $file_path"' If x=$(git rev-list -1 "$GIT_COMMIT" -not '"$before_commit"') & If you want your new file to appear only in the commits after some existing commit (“A”), then you can do this: file_path=path/to/fileīefore_commit=$(git rev-parse -verify A)įile_blob=$(git hash-object -w "$file_path") If you did use it, you would have make it conditional so that it would rewrite the date for every commit. I do not really see any reason to change the dates of the existing commits with -env-filter 'GIT_AUTHOR_DATE=…'. 'git update-index -add -cacheinfo 100644 '"$new_file"' path/to/file' \ If you want your new file to be added to every existing commit, then you can do this: new_file=$(git hash-object -w path/to/file) You could use git add, but you would first need to copy the file from some external location to the expected path ( -index-filter runs its command in a temporary GIT_WORK_TREE that is empty). Note: The examples below use the lower-level command git update-index -add instead of git add. git directory and restoring it from your backup. git filter-branch does make backup refs, but it is often easier to recover from a not-quite-right filtering by just deleting your. A simple tar archive of your entire working tree (including the. Before using git filter-branch, you should make a backup copy of your entire repository. it has more than one ref (branches, tags, etc.)), then you will probably need to use git filter-branch. Inserting a File Into a Multi- ref History Git checkout -orphan is relatively new (Git 1.7.2), but there are other ways of doing the same thing that work on older versions of Git. If you actually want your new file to be added via a new root commit (no parents), then you need something a bit different: B-C-o-o-o master The above works as long as you can name the commit that should be the parent of your new commit. The result would look like this: -A'-B'-C'-o-o-o master If you wanted to update A to include the new file (instead of creating a new commit where it was added), then use git commit -amend instead of git commit. A-N (was ",new-commit", but we delete the tag) In the following commands, use the object name (SHA-1 hash) of the commit instead of “A”.ĭo not forget to use one of the “date override” methods when you run git commit. you only have a single branch, no tags), then you can probably use git rebase to do the work. Inserting a File Into a Single ref History Your anticipated usage includes git filter-branch -env-filter also uses the environment variables mentioned above (these are part of the “env” after which the option is named see “Options” in git-filter-branch(1) and the underlying “plumbing” command git-commit-tree(1). It also has a -date option that lets you directly specify the author date. The only command that writes a new commit during normal use is git commit. See “Date Formats” in git-commit(1) or the below: Git internal format =, e.g. You can override each by supplying values through the environment variables GIT_AUTHOR_DATE and GIT_COMMITTER_DATE for any command that writes a new commit. Specifying Dates Other Than “now”Įach commit has two dates: the author date and the committer date. You are dealing with multiple, independent problems here. Also, it would be unusual to use git commit inside -index-filter. Unconditionally setting GIT_AUTHOR_DATE in an -env-filter would rewrite the date of every commit.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |