git rebase: error: cannot stat 'file': Permission denied
2022-06-04
Question I'm using git, and made a small commit followed by a large one. I decided to use git rebase to squash the two commits together before pushing them. (I've never done this before.) So I did: git rebase -i HEAD~2 This gave me my editor, where I chose to pick the earlier commit and squash the later one. When I saved, git said: error: cannot stat 'filename': Permission denied…
How to fix "corrupted" interactive rebase?
2022-06-04
Question I managed to create a little mess in my local git repository. I was trying to fix a broken commit by using the following instructions. Before running the "git commit --amend" (and after the git rebase --interactive) I decided that my changes were incorrect and so I executed "git reset HEAD --hard". Not a good idea, I tell you. Now the interactive rebase seems to be "stuck". Git shows the current branch as (|REBASE-m).…
Is there a way to get the git root directory in one command?
2022-06-04
Question Mercurial has a way of printing the root directory (that contains .hg) via hg root Is there something equivalent in git to get the directory that contains the .git directory? Answer Yes: git rev-parse --show-toplevel If you want to replicate the Mercurial command more directly, you can create an alias: git config --global alias.root 'rev-parse --show-toplevel' and now git root will function just as hg root. Note: In a submodule this will display the root directory of the submodule and not the parent repository.…
Merge (with squash) all changes from another branch as a single commit
2022-06-04
Question In Git, is there a way to merge all changes from one branch into another, but squash to a single commit at the same time? I often work on a new feature in a separate branch and will regularly commit/push - mainly for backup or to transfer what I'm working on to another machine. Mostly those commits say "Feature xxx WIP" or something redundant. Once that work is finished and I want to merge WIP branch back into master, I'd like to discard all those intermediate commits, and just a have a single clean commit.…
Git merge reports "Already up-to-date" though there is a difference
2022-06-03
Question I have a git repository with 2 branches: master and test. There are differences between master and test branches. Both branches have all changes committed. If I do: git checkout master git diff test A screen full of changes appears showing the differences. I want to merge the changes in the test branch and so do: git merge test But get the message "Already up-to-date" However, examining files under each different branch clearly shows differences.…
Pull request vs Merge request
2022-06-03
Question What is the difference between a Pull request and a Merge request? In GitHub, it's a Pull Request while in GitLab, for example, it's a Merge Request. So, is there a difference between both of these? Answer GitLab's "merge request" feature is equivalent to GitHub's "pull request" feature. Both are means of pulling changes from another branch or fork into your branch and merging the changes with your existing code.…
How can I git stash a specific file?
2022-06-02
Question How can I stash a specific file leaving the others currently modified out of the stash I am about to save? For example, if git status gives me this: younker % gst # On branch master # Your branch is ahead of 'origin/master' by 1 commit. # # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>.…