git-rewrite-history

how to re-order commits in Git non-interactively

旧街凉风 提交于 2019-12-17 22:45:05
问题 What non-interactive git command(s) achieve the change from Before to After? Before: A---B---C---D After: A---C'---B'---D' 回答1: In your case, you can rebase interactive: git rebase -i HEAD~4 Then you can just reorder your picks For example lets add three more files to our branch: git add A git commit -m "A" git add B git commit -m "B" git add C git commit -m "C" Your shortlog will be: $ git shortlog (3): A B C If you want to reorder B with C: $ git rebase -i HEAD~2 pick 1f9133d B pick 33f41be

How to amend older Git commit? [duplicate]

瘦欲@ 提交于 2019-12-17 17:18:37
问题 This question already has answers here : How to modify a specified commit? (16 answers) Closed 5 years ago . I have made 3 git commits, but have not been pushed. How can I amend the older one (ddc6859af44) and (47175e84c) which is not the most recent one? $git log commit f4074f289b8a49250b15a4f25ca4b46017454781 Date: Tue Jan 10 10:57:27 2012 -0800 commit ddc6859af448b8fd2e86dd0437c47b6014380a7f Date: Mon Jan 9 16:29:30 2012 -0800 commit 47175e84c2cb7e47520f7dde824718eae3624550 Date: Mon Jan 9

Edit the root commit in Git?

孤街浪徒 提交于 2019-12-16 20:09:05
问题 There's ways to change the message from later commits: git commit --amend # for the most recent commit git rebase --interactive master~2 # but requires *parent* How can you change the commit message of the very first commit (which has no parent)? 回答1: Assuming that you have a clean working tree, you can do the following. # checkout the root commit git checkout <sha1-of-root> # amend the commit git commit --amend # rebase all the other commits in master onto the amended root git rebase --onto

How can one change the timestamp of an old commit in Git?

老子叫甜甜 提交于 2019-12-16 19:57:23
问题 The answers to How to modify existing, unpushed commits? describe a way to amend previous commit messages that haven't yet been pushed upstream. The new messages inherit the timestamps of the original commits. This seems logical, but is there a way to also re-set the times? 回答1: Use git filter-branch with an env filter that sets GIT_AUTHOR_DATE and GIT_COMMITTER_DATE for the specific hash of the commit you're looking to fix. This will invalidate that and all future hashes. Example: If you

How to modify a specified commit?

本小妞迷上赌 提交于 2019-12-16 19:43:56
问题 I usually submit a list of commits for review. If I have the following commits: HEAD Commit3 Commit2 Commit1 ...I know that I can modify head commit with git commit --amend . But how can I modify Commit1 , given that it is not the HEAD commit? 回答1: You can use git rebase. For example, if you want to modify commit bbc643cd , run $ git rebase --interactive 'bbc643cd^' Please note the caret ^ at the end of the command, because you need actually to rebase back to the commit before the one you

How to modify a specified commit?

梦想的初衷 提交于 2019-12-16 19:41:16
问题 I usually submit a list of commits for review. If I have the following commits: HEAD Commit3 Commit2 Commit1 ...I know that I can modify head commit with git commit --amend . But how can I modify Commit1 , given that it is not the HEAD commit? 回答1: You can use git rebase. For example, if you want to modify commit bbc643cd , run $ git rebase --interactive 'bbc643cd^' Please note the caret ^ at the end of the command, because you need actually to rebase back to the commit before the one you

Removing unwanted files from history including all refs with filter-branch

旧城冷巷雨未停 提交于 2019-12-13 11:51:13
问题 I recently have cloned an SVN repository which used to have a few binaries in it, which are not needed any longer. Unfortunately, I have already pushed it to Github with the binaries inlcuded. I now want to remove these using 'git filter-branch' but I am facing some problems when it comes to tags and branches. Basically, I have created a simple shell script to remove a list of files which have been determined by the following command: git rev-list --objects --all | grep .jar > files.txt The

Rename multiple names and emails in a single pass of git-filter-branch

荒凉一梦 提交于 2019-12-13 01:04:20
问题 Is it possible to mass-rename 2 or more email addresses with a single pass of git filter-branch ? I tried adapting the code from this answer by just duplicating the if..fi clause : git filter-branch --commit-filter ' if [ "$GIT_COMMITTER_NAME" = "<Old Name 1>" ]; then GIT_COMMITTER_NAME="<New Name 1>"; GIT_AUTHOR_NAME="<New Name 1>"; GIT_COMMITTER_EMAIL="<New Email 1>"; GIT_AUTHOR_EMAIL="<New Email 1>"; git commit-tree "$@"; else git commit-tree "$@"; fi if [ "$GIT_COMMITTER_NAME" = "<Old

Rewrite git history replacing a word in every single file

不打扰是莪最后的温柔 提交于 2019-12-12 15:53:17
问题 I want to rewrite the git history of my repository with git-filter-branch to replace all occurrences of "foo.bar" with "bar.foo" in all files. How can I achieve this? Update: I've being playing with the --tree-filter parameter and I've been able to replace the word in a specified file with this: git filter-branch -f --tree-filter ' if [ -f testfile ] then sed -i s/foo.bar/bar.foo/g testfile fi ' -- --all This seems to be the closest I can get to achieve what I wanted. 回答1: The tree filter is

How to merge several Git repos into one and interleave histories

♀尐吖头ヾ 提交于 2019-12-12 10:49:05
问题 My situation is that I have two Git repositories that I need to merge into a single repository (there are actually more repos, but I can start with two). The two repositories are: The main repository, A . The second repository, B . The code in repository B has dependencies on the code in repository A (but not vice versa), and the histories of both repositories follow each other in a chronological fashion - roughly (i.e. a specific commit in repo B will typically require a commit from repo A