git-commit

Purging file from Git repo failed, unable to create new backup

自古美人都是妖i 提交于 2019-11-27 05:02:26
问题 I tried to remove a file from my remote repo by running: git filter-branch --index-filter 'git rm --cached --ignore-unmatch Rakefile' HEAD But Git complains that Cannot create new backup. A previous backup already exists in refs/original/ Force overwriting the backup with -f rm: cannot remove /.git-rewrite/backup-refs : Permission denied rm: cannot remove directory /.git-rewrite : Directory not empty This was after I already deleted the .git-rewrite directory on Windows. How can I remove that

Git commit style: All changed files at once or one at a time?

こ雲淡風輕ζ 提交于 2019-11-27 04:31:01
问题 I am saving my work at night with a single commit for many files. I wonder if it would be better to commit for each file but this seems like a lot more work. I have no problem with the way things are now but I plan to put my code on GitHub and I want it to be easy to understand. I'm wondering what the rest of you who use git are doing. Also if you could kind of spell it out for me. I'm new to Git and I've been using TortoiseGit and gitk in Windows. 回答1: When to commit and what to commit is an

Git commit that doesn't override original authors in git blame

微笑、不失礼 提交于 2019-11-27 03:46:00
I've used a perl script to modify all tab characters in a php git repository and changed them all to 4 spaces. $ find -iname \*.php -exec perl -pi -e "s/\t/ /g" {} \ I can commit this change with git commit , but it will mark me as the author of all changed lines inside git blame after this commit is made. Is there any way to commit this massive change that doesn't mark me as the author of the changed lines, but retains the original author? That's a lot of history we don't really want to lose in our project. Our purpose in replacing tabs with 4 spaces is not to make things appear different in

Removing multiple files from a Git repo that have already been deleted from disk

醉酒当歌 提交于 2019-11-27 01:54:44
I have a Git repo that I have deleted four files from using rm ( not git rm ), and my Git status looks like this: # deleted: file1.txt # deleted: file2.txt # deleted: file3.txt # deleted: file4.txt How do I remove these files from Git without having to manually go through and add each file like this: git rm file1 file2 file3 file4 Ideally, I'm looking for something that works in the same way that git add . does, if that's possible. For Git 1.x $ git add -u This tells git to automatically stage tracked files -- including deleting the previously tracked files. For Git 2.0 To stage your whole

Remove empty commits in git

梦想的初衷 提交于 2019-11-27 01:48:41
问题 I just migrated a project from Mercurial to Git. Mercurial adds empty commits when you add tags, so I ended up with empty commits in Git that I would like to remove. How do I remove empty commits (commits that do not have any files in them) from Git? Thanks. 回答1: One simple (but slow) way to do this is with git filter-branch and --prune-empty . With no other filters, no other commits will be altered, but any empty ones will be discarded (which will cause all subsequent commits to have new

git rejected push non-fast-forward

蹲街弑〆低调 提交于 2019-11-27 01:22:39
问题 I am quite new to git, and I had been working on a small side project for the last 2 months and had been pushing stuff onto bitbucket with no problems. A couple of days ago, I zipped my project folder (since I had to reinstall my Linux OS) and now unzipped this after my reinstallation of Linux OS. So, now, I went to my project folder, kept happily working and finally did: git add -A && git commit -m "modified code" && git push origin master ..which is what I usually do.. and I get: To https:/

Reset all changes after last commit in git

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 23:44:50
问题 How can I undo every change made to my directory after the last commit, including deleting added files, resetting modified files, and adding back deleted files? 回答1: First reset the changes git reset HEAD --hard then clean out everything untracked. If you want to keep files that are not tracked due to .gitignore , be careful with this command. git clean -fd 回答2: How can I undo every change made to my directory after the last commit, including deleting added files, resetting modified files,

Accidentally pushed commit: change git commit message

一曲冷凌霜 提交于 2019-11-26 23:31:35
In my local repo I have one commit with an incorrect commit message. I've already published the incorrect commit message with git push . Now the remote repo (which is GitHub-hosted) has the incorrect commit message, too. I've already tried git commit --amend , but found that it will not work for me in this situation because I've made additional commits since the incorrect one. How would you fix this situation? Dan Moulding Easiest solution ( but please read this whole answer before doing this ): git rebase -i <hash-of-commit-preceding-the-incorrect-one> In the editor that opens, change pick to

Skip Git commit hooks

僤鯓⒐⒋嵵緔 提交于 2019-11-26 23:29:08
I'm looking at a git hook which looks for print statements in Python code. If a print statement is found, it prevents the git commit. I want to override this hook and I was told that there is a command to do so. I haven't been able to find it. Any thoughts? Maybe (from git commit man page ): git commit --no-verify -n --no-verify This option bypasses the pre-commit and commit-msg hooks. See also githooks(5) . As commented by Blaise , -n can have a different role for certain commands. For instance, git push -n is actually a dry-run push. Only git push --no-verify would skip the hook. Note: Git 2

Find commit where file was added

和自甴很熟 提交于 2019-11-26 18:05:02
Say I have a file foo.js that was committed some time ago. I would like to simply find the commit where this file was first added. After reading the answers and my own tinkering, this works for me git log --follow --diff-filter=A --find-renames=40% foo.js stelterd Here's simpler, "pure Git" way to do it, with no pipeline needed: git log --diff-filter=A -- foo.js Check the documentation. You can do the same thing for Deleted, Modified, etc. https://git-scm.com/docs/git-log#Documentation/git-log.txt---diff-filterACDMRTUXB82308203 I have a handy alias for this, because I always forget it: git