I have been converting old SVN repos to GIT. I have gotten the branches and tags to convert. Including making SVN tags real tags in GIT.
However, I would like to add a gitignore to the very first commit in the newly created GIT repo. I want it to be as if the file had always been there. So all the commits that followed (on master or in branches) would now have this file as the parent tree(s) would lead back the the first commit.
It seems that some form of git rebase or git filter-branch --tree-filter is what I need. I have tried each of these but I end up with disconnected branches.
Usage. Go to any particular repo's landing page (e.g. like the one you're on) and click the bookmarklet, which will take you to the first page (initial commit). By default, it tracks the master branch, but if you change the branch on the landing page, it will go to that branch's first commit.
Use git commit --amend to change your latest log message. Use git commit --amend to make modifications to the most recent commit. Use git rebase to combine commits and modify history of a branch.
On your computer, move the file you'd like to upload to GitHub into the local directory that was created when you cloned the repository. Open Terminal . Change the current working directory to your local repository. Stage the file for commit to your local repository.
In case anyone needs to do this in the future, here's an easier solution. I recently had to modify an early commit because of a problematic typo in the commit message. This works for changing anything about a previous commit. I modified Charles Bailey's answer here.
# Go back to the commit you want to change (detach HEAD)
git checkout <sha1_for_commit_to_change>
# Make any changes now (add your new file) then add them to the index
git add <new_files>
# amend the current commit
git commit --amend
# temporarily tag this new commit
# (or you could remember the new commit sha1 manually)
git tag tmp
# go back to the original branch (assume master for this example)
git checkout master
# Replay all the commits after the change onto the new initial commit
git rebase --preserve-merges --onto tmp <sha1_for_commit_to_change>
# remove the temporary tag
git tag -d tmp
Note that this will change all of your commit IDs following the amended commit, so it's not recommended on a public repository. Also, you'll have to recreate all of your tags
Do this on a clean working tree, on a new clone if you wish:
$ git checkout -b withgitignore $firstcommithash
$ git add .gitignore
$ git commit --amend
$ for branch in branch1 branch2 branch3 ... ; do
git checkout $branch
git rebase withgitignore
done
Untested ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With