git-rewrite-history

Remove refs/original/heads/master from git repo after filter-branch --tree-filter?

岁酱吖の 提交于 2019-11-26 10:06:17
问题 I had the same question as asked here: New git repository in root directory to subsume an exist repository in a sub-directory I followed this answer here: New git repository in root directory to subsume an exist repository in a sub-directory Now, gitk --all shows two histories: one culminating in the current master , and one named original/refs/heads/master . I don\'t know what this second history is, or how to remove it from the repo. I don\'t need two histories in my repository. How do I

Rebasing a Git merge commit

假如想象 提交于 2019-11-26 09:15:12
问题 Take the following case: I have some work in a topic branch and now I\'m ready to merge back to master: * eb3b733 3 [master] [origin/master] | * b62cae6 2 [topic] |/ * 38abeae 1 I perform the merge from master, resolve the conflicts and now I have: * 8101fe3 Merge branch \'topic\' [master] |\\ | * b62cae6 2 [topic] * | eb3b733 3 [origin/master] |/ * 38abeae 1 Now, the merge took me some time, so I do another fetch and notice that the remote master branch has new changes: * 8101fe3 Merge

Git commands that could break/rewrite the history

只谈情不闲聊 提交于 2019-11-26 06:08:00
问题 Can you provide a list of (all, or the most common) the operations or commands that can compromise the history in git? What should be absolutely avoided? Amend a commit after a push of this one ( git commit / git push / git commit --amend ) Rebase toward something that has already pushed I would like this question (if it has not already asked before somewhere else) to become some kind of reference on the common avoidable operations on git . Moreover I use git reset a lot, but am not

Remove file from git repository (history)

梦想的初衷 提交于 2019-11-26 03:48:17
问题 (solved, see bottom of the question body) Looking for this for a long time now, what I have till now is: http://dound.com/2009/04/git-forever-remove-files-or-folders-from-history/ and http://progit.org/book/ch9-7.html Pretty much the same method, but both of them leave objects in pack files... Stuck. What I tried: git filter-branch --index-filter \'git rm --cached --ignore-unmatch file_name\' rm -Rf .git/refs/original rm -Rf .git/logs/ git gc Still have files in the pack, and this is how I

How to squash all git commits into one?

旧时模样 提交于 2019-11-26 03:21:53
问题 How do you squash your entire repository down to the first commit? I can rebase to the first commit, but that would leave me with 2 commits. Is there a way to reference the commit before the first one? 回答1: Perhaps the easiest way is to just create a new repository with current state of the working copy. If you want to keep all the commit messages you could first do git log > original.log and then edit that for your initial commit message in the new repository: rm -rf .git git init git add .

Combine the first two commits of a Git repository?

走远了吗. 提交于 2019-11-26 01:48:19
问题 Suppose you have a history containing the three commits A, B and C : A-B-C I would like to combine the two commits A and B to one commit AB : AB-C I tried git rebase -i A which opens up my editor with the following contents: pick e97a17b B pick asd314f C I change this to squash e97a17b B pick asd314f C Then Git 1.6.0.4 says: Cannot \'squash\' without a previous commit Is there a way or is this just impossible? 回答1: Use git rebase -i --root as of Git version 1.7.12. In the interactive rebase

How to modify existing, unpushed commit messages?

感情迁移 提交于 2019-11-25 23:57:16
问题 This post is a Community Wiki . Edit existing answers to improve this post. It is not currently accepting new answers. I wrote the wrong thing in a commit message. How can I change the message? The commit has not been pushed yet. 回答1: Amending the most recent commit message git commit --amend will open your editor, allowing you to change the commit message of the most recent commit. Additionally, you can set the commit message directly in the command line with: git commit --amend -m "New

Remove sensitive files and their commits from Git history

对着背影说爱祢 提交于 2019-11-25 23:56:44
问题 I would like to put a Git project on GitHub but it contains certain files with sensitive data (usernames and passwords, like /config/deploy.rb for capistrano). I know I can add these filenames to .gitignore , but this would not remove their history within Git. I also don\'t want to start over again by deleting the /.git directory. Is there a way to remove all traces of a particular file in your Git history? 回答1: For all practical purposes, the first thing you should be worried about is

Combine the first two commits of a Git repository?

女生的网名这么多〃 提交于 2019-11-25 23:28:56
Suppose you have a history containing the three commits A, B and C : A-B-C I would like to combine the two commits A and B to one commit AB : AB-C I tried git rebase -i A which opens up my editor with the following contents: pick e97a17b B pick asd314f C I change this to squash e97a17b B pick asd314f C Then Git 1.6.0.4 says: Cannot 'squash' without a previous commit Is there a way or is this just impossible? kostmo Use git rebase -i --root as of Git version 1.7.12 . In the interactive rebase file, change the second line of commit B to squash and leave the other lines at pick : pick f4202da A

How do you fix a bad merge, and replay your good commits onto a fixed merge?

Deadly 提交于 2019-11-25 22:18:30
问题 I accidentally committed an unwanted file ( filename.orig while resolving a merge) to my repository several commits ago, without me noticing it until now. I want to completely delete the file from the repository history. Is it possible to rewrite the change history such that filename.orig was never added to the repository in the first place? 回答1: Please don't use this recipe if your situation is not the one described in the question. This recipe is for fixing a bad merge, and replaying your