summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--_posts/2009-09-09-removing-sensitive-data.markdown (renamed from _posts/2009-09-09-removing-sensitive-data.textile)32
1 files changed, 19 insertions, 13 deletions
diff --git a/_posts/2009-09-09-removing-sensitive-data.textile b/_posts/2009-09-09-removing-sensitive-data.markdown
index c9ba7d7..02f0c98 100644
--- a/_posts/2009-09-09-removing-sensitive-data.textile
+++ b/_posts/2009-09-09-removing-sensitive-data.markdown
@@ -5,15 +5,17 @@ description: Dealing with accidentally committed passwords or other sensitive in
categories: popular git_ninjutsu
---
-From time to time users accidentally commit data like passwords or keys into a git repo. While you can use @git rm@ to remove the file, it will still be in the repo's history. Fortunately, git makes it fairly simple to remove the file from the entire repo history.
+From time to time users accidentally commit data like passwords or keys into a git repo. While you can use `git rm` to remove the file, it will still be in the repo's history. Fortunately, git makes it fairly simple to remove the file from the entire repo history.
-h2. Change your password
+Change your password
+--------------------
This step should be blatantly obvious, but some users still skip it. If you committed a password, change it! If you committed a key, generate a new one. Once the commit has been pushed you should consider the data to be compromised. Period.
-h2. Purge the file from your repo
+Purge the file from your repo
+-----------------------------
-Now that the password is changed, you want to remove the file from history and add it to the @.gitignore@ to ensure it is not accidentally re-committed. For our examples, we're going to remove @Rakefile@ from the "GitHub gem":http://github.com/defunkt/github-gem repo.
+Now that the password is changed, you want to remove the file from history and add it to the `.gitignore` to ensure it is not accidentally re-committed. For our examples, we're going to remove `Rakefile` from the "GitHub gem":http://github.com/defunkt/github-gem repo.
<pre class="terminal">[tekkub@tekBook: ~/tmp master*] $ git clone git@github.com:defunkt/github-gem.git
Initialized empty Git repository in /Users/tekkub/tmp/github-gem/.git/
@@ -29,9 +31,9 @@ Resolving deltas: 100% (724/724), done.
Rewrite 48dc599c80e20527ed902928085e7861e6b3cbe6 (266/266)
Ref 'refs/heads/master' was rewritten</pre>
-This command will run the entire history of the master branch and change any commit that involved the file @Rakefile@, and any commits afterwards. Now that we've erased the file from history, lets ensure that we don't accidentally commit it again.
+This command will run the entire history of the master branch and change any commit that involved the file `Rakefile`, and any commits afterwards. Now that we've erased the file from history, lets ensure that we don't accidentally commit it again.
-If you wish to retain tags you must specify <code>--tag-name-filter "cat"</code>, but note that *this will overwrite your existing tags*.
+If you wish to retain tags you must specify `--tag-name-filter "cat"`, but note that *this will overwrite your existing tags*.
<pre class="terminal">[tekkub@tekBook: ~/tmp/github-gem master] $ echo "Rakefile" >> .gitignore
@@ -41,7 +43,7 @@ If you wish to retain tags you must specify <code>--tag-name-filter "cat"</code>
[master 051452f] Add Rakefile to .gitignore
1 files changed, 1 insertions(+), 0 deletions(-)</pre>
-This would be a good time to double-check that you've removed everything that you wanted to from the history. Note that @git filter-branch@ only works on one branch at a time, so you may need to perform the cleanup on other branches as well. This could be problematic if the branch has a complex merge history. If we're happy with the state of the repo, we need to force-push the changes to overwrite the remote repo.
+This would be a good time to double-check that you've removed everything that you wanted to from the history. Note that `git filter-branch` only works on one branch at a time, so you may need to perform the cleanup on other branches as well. This could be problematic if the branch has a complex merge history. If we're happy with the state of the repo, we need to force-push the changes to overwrite the remote repo.
<pre class="terminal">[tekkub@tekBook: ~/tmp/github-gem master] $ git push origin master --force
Counting objects: 1074, done.
@@ -54,7 +56,7 @@ To git@github.com:defunkt/github-gem.git
h3. Cleanup and reclaiming space
-While @git filter-branch@ rewrites the history for you, the objects will remain in your local repo until they've been dereferenced and garbage collected. If you are working in your main repo you might want to force these objects to be purged.
+While `git filter-branch` rewrites the history for you, the objects will remain in your local repo until they've been dereferenced and garbage collected. If you are working in your main repo you might want to force these objects to be purged.
<pre class="terminal">[tekkub@tekBook: ~/tmp/github-gem master] $ rm -rf .git/refs/original/
[tekkub@tekBook: ~/tmp/github-gem master] $ git reflog expire --all
@@ -67,19 +69,23 @@ Total 1746 (delta 993), reused 0 (delta 0)</pre>
Note that pushing the branch to a new or empty GitHub repo and then making a fresh clone from GitHub will have the same effect.
-h2. Dealing with collaborators
+Dealing with collaborators
+--------------------------
-You may have collaborators that pulled your tainted branch and created their own branches off of it. After they fetch your new branch, they will need to use @git rebase@ on their own branches to rebase them on top of the new one. The collab should also ensure that their branch doesn't reintroduce the file, as this will override the @.gitignore@ file. *Make sure your collab uses rebase and not merge,* otherwise he will just reintroduce the file and the entire tainted history... and likely encounter some merge conflicts.
+You may have collaborators that pulled your tainted branch and created their own branches off of it. After they fetch your new branch, they will need to use `git rebase` on their own branches to rebase them on top of the new one. The collab should also ensure that their branch doesn't reintroduce the file, as this will override the `.gitignore` file. *Make sure your collab uses rebase and not merge,* otherwise he will just reintroduce the file and the entire tainted history... and likely encounter some merge conflicts.
-h2. Cached data on GitHub
+Cached data on GitHub
+---------------------
Be warned that force-pushing does not erase commits on the remote repo, it simply introduces new ones and moves the branch pointer to point to them. If you are worried about users accessing the bad commits directly via SHA1, you will have to delete the repo and recreate it. If the commits were viewed online the pages may also be cached. Check for cached pages after you recreate the repo, if you find any open a ticket on "GitHub Support":http://support.github.com and provide links so staff can purge them from the cache.
-h2. Avoiding accidental commits in the future
+Avoiding accidental commits in the future
+-----------------------------------------
There are a few simple tricks to avoid committing things you don't want committed. The first, and simplest, is to use a visual tool like git-gui or "gitx":http://gitx.frim.nl/ to make your commits. This lets you see exactly what you're committing, and ensure that only the files you want are added to the repo. If you're working form the command line, avoid the catch-all commands `git add .` and `git commit -a`, instead use `git add filename` and `git rm filename` to individually stage files. You can also use `git add --interactive` to review each changed file and stage it, or part of it, for commit. If you're working from the command line, you can also use `git diff --cached` to see what changes you have staged for commit. This is the exact diff that your commit will have as long as you commit without the `-a` flag.
-h2. Other reading
+Other reading
+-------------
* "git-filter-branch documentation":http://www.kernel.org/pub/software/scm/git/docs/git-filter-branch.html
* "Git user manual - Cleaning up history":http://www.kernel.org/pub/software/scm/git/docs/user-manual.html#cleaning-up-history \ No newline at end of file