When you want to do a git diff but do not care about the full diff and just want to know which files changed, use the --name-only switch:

...app/models/user.rb features/sign_in.feature To include some brief information about changed lines, use the --stat switch: $ git diff --stat app/controllers/sessions_controller.rb | 8 +- app/models/user.rb | 30 ++++ features/sign_in.feature | 136 +++++++++++++++++ The output of --stat is nicely colored...

stackoverflow.com

If your git index for some reason becomes invalid, no need to worry. Your index is corrupt when you see this error running usual git commands like git pull, git...

...there. Fix it by first removing the index file, then resetting the branch: rm .git/index git reset You should be all good now. To be safe, make a backup of...

Put this in your ~/.claude/settings.json: { "sandbox": { "enabled": true, "autoAllowBashIfSandboxed": true, "allowUnsandboxedCommands": false, "excludedCommands": [ "git checkout *", "git checkout", "git cherry-pick *", "git merge *", "git merge", "git pull *", "git pull",

...rebase *", "git rebase", "git reset *", "git restore *", "git revert *", "git stash *", "git stash", "git subtree *", "git switch *" ], "network": { "allowAllUnixSockets": true }, "filesystem": { "denyRead": [ "~/" ], "allowRead": [ ".", "~/.rbenv", "~/.nvm", "~/.claude", "~/.cache/node/corepack", "~/.cache/ms-playwright", "~/.config/glab-cli", "~/.config/mise...

kernel.org

If you say git stash, your stashed changes will be identified with an automatically generated message: $ git stash Saved working directory and index state WIP on master: 77af0df Merge branch...

...if you stash often. Of course, there is a way to do it with git: $ git stash save doing crazy things Saved working directory and index state On master: doing...

When you have files in your .gitignore they won't be considered for changes, but still you might want to get rid of them, e.g. because they clutter your file...

While a regular git clean will ignore them as well, passing the -x switch changes that: git clean -x If you want to see what would happen first, make...

...another branch or past commit without doing a complete checkout, you can either use git show branch:file git show commit:file to display, or check out the file into...

...your working directory with git checkout branch -- file git checkout commit -- file

richfrog.curzons.net

...up a cmd and put the full path to PuTTY's plink.exe into the GIT_SSH environment variable, e.g.: set GIT_SSH=D:\PuTTY\plink.exe You can then use Git...

...like you would on any sane operating system. Just go ahead and git clone, git pull, etc. Also, you may want to add the environment variable under the Windows system...

...find a version containing the regular expression foo in the history of any branch: git grep foo $(git rev-list --all) You may also limit the search to a file...

...extension, e.g. Ruby files (.rb) like this: git grep foo $(git rev-list --all) -- *.rb

In order to clone a git repository including all branches and tags you need to use two parameters when cloning the old and pushing to the new repository respectively:

...clone --bare http://example.com/old-repo.git cd old-repo git push --mirror http://example.com/new-repo.git Of course, the URLs to your repository might look different depending on the protocol used, username...

git apply allows you to apply a diff onto your HEAD. Most often you can achieve the same result with a rebase & merge. Example: master commit1 - commit3 feature-branch \ commit2...

git checkout feature-branch git reset --hard commit3 git diff ..commit4 | git apply master commit1 - commit3 feature-branch \ Unstaged commit 2 & 4 You can also create a patch and...

Merging .po-files with Git is painful. There have been attempts of making Git more clever when trying to merge .po-files. I believe however that this is not enough...

...invalid merges I additionally disable merging for po files altogether, by adding the following .gitattributes file to the root of the repository: *.po merge=binary *.pot merge=binary

If you modified git's history and the change was already pushed, you will usually get a ! [rejected] my-branch -> my-branch (non-fast-forward) error, when trying to push...

...You can force the push, with git push --force origin my-branch Careful: You might lose history. Unless your git is configured to push only the current branch, you must...

Instead of showing you two lines for each change, Git allows you to highlight changes in a line explicitly: git diff --word-diff some_file Hello [-world-]{+universe+}!

...unhandy to use.\ You maybe just want the diff put into your terminal: PAGER='' git diff --word-diff some_file

Every time you amend, rebase or reset, git commits get "overwritten". However, git still allows you to checkout those commits using their SHA1, given you can find it.

git reflog # or git reflog show [BRANCH] This will show a list of all commits the branch has recently pointed to. Git might garbage collect those...

You might get the above error message when cloning certain git repositories (for example the rails repository). It indicates that there is a malformed timestamp in some commit, and your...

...git installation is configured to validate it. As a workaround, you can disable the validation using git config --global fetch.fsckobjects false This settings seems to be the default for most...

If git gives you an error message such as "fatal: bad config file line 123 in .git/config" after you tried to checkout a branch with a very long branch name...

...you very likely come across a bug in git version < 1.8. You should ask someone with a newer git version (someone pushed the branch right?) to rename the branch to...

To display a list of your current Git remotes and...

...their endpoints, you can say git remote -v The output looks like this: brady8 https://github.com/brady8/aegis.git (fetch) brady8 https://github.com/brady8/aegis.git (push) origin git@github.com:makandra/aegis.git (fetch) origin git@github.com:makandra/aegis.git...

...your ~/.bashrc: export PS1='\[\033[01;32m\]\h\[\033[01;34m\] \w\[\033[31m\]$(__git_ps1 "(%s)") \[\033[01;34m\]$\[\033[00m\] ' Reload the changes by saying source ~/.bashrc

...some customized prompts that also show the current Git prompt, see the examples section at the bottom of our bash prompt customizing card...

durdn.com

This article contains: Making ‘git diff’ wrap long lines Set a global proxy Clone only a specific branch Diff file against remote branch List all deleted files in the repository...

...Search for a string in all revisions of entire git history Apply a patch from another (unrelated) local repository Making a more recent branch the new master Adding an initial...

...sometimes want to use an external tool for viewing a diff, you can use git difftool. E.g. viewing git diff with meld: git difftool --tool=meld For each file in...

...a file by mistake, you can unstage it (but keep local changes) by saying git reset HEAD path/to/file This is also what git status will tell you.

...for conflicts, too, if git checkout -- does not (although git tells you it would...

You can tell git to ignore different kinds and amounts of whitespace when merging or cherry-picking. This often occurs when you changed indentation, or converted tabs to spaces.

git merge -Xignore-space-change or git cherry-pick -Xignore-space-change

...for your project. Go to Project Settings / Version Control and set the director to Git...

makandra dev
stackoverflow.com

When there's a Gemfile.lock in your working directory that you cannot remove by either checkout, reset [--hard], stash, probably...