git-commit

Skip Git commit hooks

*爱你&永不变心* 提交于 2019-11-26 07:53:49
问题 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? 回答1: 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

How do I make a Git commit in the past?

孤街醉人 提交于 2019-11-26 06:09:28
问题 I\'m converting everything over to Git for my own personal use and I found some old versions of a file already in the repository. How do I commit it to the history in the correct order according the the file\'s \"date modified\" so I have an accurate history of the file? I was told something like this would work: git filter-branch --env-filter=\"GIT_AUTHOR_DATE=... --index-filter \"git commit path/to/file --date \" --tag-name-filter cat -- --all 回答1: The advice you were given is flawed.

How can I recover from an erronous git push -f origin master?

守給你的承諾、 提交于 2019-11-26 03:51:18
问题 I just committed the wrong source to my project using --force option. Is it possible to revert? I understand that all previous branches have been overwritten using -f option, so I may have screwed up my previous revisions. 回答1: Git generally doesn't throw anything away, but recovering from this may still be tricky. If you have the correct source then you could just push it into the remote with the --force option. Git won't have deleted any branches unless you told it to. If you have actually

How does git commit --amend work, exactly?

我们两清 提交于 2019-11-26 03:44:59
问题 I have seen GIT commit --amend in detached HEAD state. The question requires the answer to be more complex than needs be. I\'d like to understand just how git commit --amend works in a normal HEAD situation. 回答1: Assume that you're in a clean working state and that your repo looks as follows: If you then run git commit --amend write a commit message, save and quit your editor, the following happens: Your staging area—which, if you haven't staged any new changes, will be identical to commit

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

南楼画角 提交于 2019-11-26 03:22:46
问题 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. 回答1: For Git 1.x $ git add -u This tells git to

Link to the issue number on GitHub within a commit message

风格不统一 提交于 2019-11-26 02:59:26
问题 Is it somehow possible to automatically have a link to GitHub issue number in the git commit message? 回答1: Just include #xxx in your commit message to reference an issue without closing it. With new GitHub issues 2.0 you can use these synonyms to reference an issue and close it (in your commit message): fix #xxx fixes #xxx fixed #xxx close #xxx closes #xxx closed #xxx resolve #xxx resolves #xxx resolved #xxx You can also substitute #xxx with gh-xxx . Referencing and closing issues across

Remove files from Git commit

梦想与她 提交于 2019-11-26 02:39:22
问题 I am using Git and I have committed few files using git commit -a Later, I found that a file had mistakenly been added to the commit. How can I remove a file from the last commit? 回答1: I think other answers here are wrong, because this is a question of moving the mistakenly committed files back to the staging area from the previous commit, without cancelling the changes done to them. This can be done like Paritosh Singh suggested: git reset --soft HEAD^ or git reset --soft HEAD~1 Then reset

What are the differences between “git commit” and “git push”?

余生长醉 提交于 2019-11-26 02:38:59
问题 In a Git tutorial I\'m going through, git commit is used to store the changes you\'ve made. What is git push used for then? 回答1: Basically git commit " records changes to the repository " while git push " updates remote refs along with associated objects ". So the first one is used in connection with your local repository, while the latter one is used to interact with a remote repository. Here is a nice picture from Oliver Steele, that explains the git model and the commands: Read more about

Make the current commit the only (initial) commit in a Git repository?

纵饮孤独 提交于 2019-11-26 01:43:33
问题 I currently have a local Git repository, which I push to a Github repository. The local repository has ~10 commits, and the Github repository is a synchronised duplicate of this. What I\'d like to do is remove ALL the version history from the local Git repository, so the current contents of the repository appear as the only commit (and therefore older versions of files within the repository are not stored). I\'d then like to push these changes to Github. I have investigated Git rebase, but

Undo git reset --hard with uncommitted files in the staging area

让人想犯罪 __ 提交于 2019-11-26 01:05:58
问题 I am trying to recover my work. I stupidly did git reset --hard , but before that I\'ve done only get add . and didn\'t do git commit . Please help! Here is my log: MacBookPro:api user$ git status # On branch master # Changes to be committed: # (use \"git reset HEAD <file>...\" to unstage) # modified: .gitignore ... MacBookPro:api user$ git reset --hard HEAD is now at ff546fa added new strucuture for api Is it possible to undo git reset --hard in this situation? 回答1: You should be able to