moving committed (but not pushed) changes to a new branch after pull
2023-01-22
Question I've done a fair bit of work ("Your branch is ahead of 'origin/master' by 37 commits.") which really should have gone into its own branch rather than into master. These commits only exist on my local machine and have not been pushed to origin, but the situation is complicated somewhat in that other devs have been pushing to origin/master and I've pulled those changes. How do I retroactively move my 37 local commits onto a new branch?…
How do I pull from a Git repository through an HTTP proxy?
2023-01-21
Question Note: while the use-case described is about using submodules within a project, the same applies to a normal git clone of a repository over HTTP. I have a project under Git control. I'd like to add a submodule: git submodule add http://github.com/jscruggs/metric_fu.git vendor/plugins/metric_fu But I get ... got 1b0313f016d98e556396c91d08127c59722762d0 got 4c42d44a9221209293e5f3eb7e662a1571b09421 got b0d6414e3ca5c2fb4b95b7712c7edbf7d2becac7 error: Unable to find abc07fcf79aebed56497e3894c6c3c06046f913a under http://github.com/jscruggs/metri... Cannot obtain needed commit abc07fcf79aebed56497e3894c6c3c06046f913a while processing commit ee576543b3a0820cc966cc10cc41e6ffb3415658. fatal: Fetch failed.…
How can I revert multiple Git commits?
2023-01-20
Question I have a Git repository that looks like this: A <- B <- C <- D <- HEAD I want the head of the branch to point to A, i.e., I want B, C, D, and HEAD to disappear and I want head to be synonymous with A. It sounds like I can either try to rebase (doesn't apply, since I've pushed changes in between), or revert. But how do I revert multiple commits?…
Is there a way to make git pull automatically update submodules?
2023-01-19
Question Is there a way to automatically have git submodule update (or preferably git submodule update --init called whenever git pull is done? Looking for a git config setting, or a git alias to help with this. Answer As of Git 2.14, you can use git pull --recurse-submodules (and alias it to whatever you like). As of Git 2.15, you could set submodule.recurse to true to enable the desired behaviour.…
View the change history of a file using Git versioning
2023-01-19
Question How do I view the history of an individual file with complete details of what has changed? git log -- [filename] shows me the commit history of a file, but how do I see the file content that changed? Answer This lets Git generate the patches for each log entry: git log -p -- filename See git help log for more options — it can actually do a lot of nice things.…
Git: list only "untracked" files (also, custom commands)
2023-01-18
Question Is there a way to use a command like git ls-files to show only untracked files? The reason I'm asking is because I use the following command to process all deleted files: git ls-files -d | xargs git rm I'd like something similar for untracked files: git some-command --some-options | xargs git add I was able to find the -o option to git ls-files, but this isn't what I want because it also shows ignored files.…
How do I "un-revert" a reverted Git commit?
2023-01-17
Question Given a change that has been committed using commit, and then reverted using revert, what is the best way to then undo that revert? Ideally, this should be done with a new commit, so as to not re-write history. Answer git cherry-pick <original commit sha> Will make a copy of the original commit, essentially re-applying the commit Reverting the revert will do the same thing, with a messier commit message: git revert <commit sha of the revert>…