Why does git perform fast-forward merges by default?
2022-05-07
Question Coming from mercurial, I use branches to organize features. Naturally, I want to see this work-flow in my history as well. I started my new project using git and finished my first feature. When merging the feature, I realized git uses fast-forward, i.e. it applies my changes directly to the master branch if possible and forgets about my branch. So to think into the future: I'm the only one working on this project.…
How do I modify a specific commit?
2022-05-06
Question I have the following commit history: HEAD HEAD~ HEAD~2 HEAD~3 git commit --amend modifies the current HEAD commit. But how do I modify HEAD~3? Answer Use git rebase. For example, to modify commit bbc643cd, run: git rebase --interactive bbc643cd~ Please note the tilde ~ at the end of the command, because you need to reapply commits on top of the previous commit of bbc643cd (i.e. bbc643cd~). In the default editor, modify pick to edit in the line mentioning bbc643cd.…
How do you change the capitalization of filenames in Git?
2022-05-06
Question I am trying to rename a file to have different capitalization from what it had before: git mv src/collision/b2AABB.js src/collision/B2AABB.js fatal: destination exists, source=src/collision/b2AABB.js, destination=src/collision/B2AABB.js As you can see, Git throws a fit over this. I tried renaming using just the plain old mv command as well, but Git doesn't pick up the rename (as a rename or as a new untracked file). How can I change a file to have a different capitalization of the same name?…
Can I recover a branch after its deletion in Git?
2022-05-05
Question If I run git branch -d XYZ, is there a way to recover the branch? Is there a way to go back as if I didn't run the delete branch command? Answer Yes, you should be able to do git reflog --no-abbrev and find the SHA1 for the commit at the tip of your deleted branch, then just git checkout [sha]. And once you're at that commit, you can just git checkout -b [branchname] to recreate the branch from there.…
How to convert a Git shallow clone to a full clone?
2022-05-05
Question Follow-up of this so-question: if I have a shallow clone, how to fetch all older commits to make it a full clone? Answer The below command (git version 1.8.3) will convert the shallow clone to regular one git fetch --unshallow Then, to get access to all the branches on origin (thanks @Peter in the comments) git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" git fetch origin
How to list all Git tags?
2022-05-05
Question In my repository, I have created tags using the following commands. git tag v1.0.0 -m 'finally a stable release' git tag v2.0.0 -m 'oops, there was still a major bug!' How do you list all the tags in the repository? Answer git tag should be enough. See git tag man page You also have: git tag -l <pattern> List tags with names that match the given pattern (or all if no pattern is given).…
How to remove the first commit in git?
2022-05-05
Question I am curious about how to remove the first commit in git. What is the revision before committing any thing? Does this revision have a name or tag? Answer For me, the most secure way is to use the update-ref command: git update-ref -d HEAD It will delete the named reference HEAD, so it will reset (softly, you will not lose your work) ALL your commits of your current branch.…