git-commit

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

早过忘川 提交于 2019-11-26 00:27:29
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? Mark Longair You should be able to recover any files back that you added to the index (e.g, as in your situation, with git add . )

Commit only part of a file in Git

佐手、 提交于 2019-11-26 00:13:26
问题 When I make changes to a file in Git, how can I commit only some of the changes? For example, how could I commit only 15 lines out of 30 lines that have been changed in a file? 回答1: You can use git add --patch <filename> (or -p for short), and git will begin to break down your file into what it thinks are sensible "hunks" (portions of the file). It will then prompt you with this question: Stage this hunk [y,n,q,a,d,/,j,J,g,s,e,?]? Here is a description of each option: y stage this hunk for

How do I commit case-sensitive only filename changes in Git?

浪子不回头ぞ 提交于 2019-11-26 00:05:26
问题 I have changed a few files name by de-capitalize the first letter, as in Name.jpg to name.jpg . Git does not recognize this changes and I had to delete the files and upload them again. Is there a way that Git can be case-sensitive when checking for changes in file names? I have not made any changes to the file itself. 回答1: You can use git mv: git mv -f OldFileNameCase newfilenamecase 回答2: Git has a configuration setting that tells it whether to be case sensitive or insensitive: core

How do I push amended commit to the remote Git repository?

我与影子孤独终老i 提交于 2019-11-25 23:59:53
问题 When I\'ve worked a bit with my source code, I did my usual thing commit and then I pushed to a remote repository. But then I noticed I forgot to organize my imports in the source code. So I do the amend command to replace the previous commit: > git commit --amend Unfortunately the commit can\'t be pushed back to the repository. It is rejected like this: > git push origin To //my.remote.repo.com/stuff.git/ ! [rejected] master -> master (non-fast forward) error: failed to push some refs to \'/

How to modify existing, unpushed commit messages?

感情迁移 提交于 2019-11-25 23:57:16
问题 This post is a Community Wiki . Edit existing answers to improve this post. It is not currently accepting new answers. I wrote the wrong thing in a commit message. How can I change the message? The commit has not been pushed yet. 回答1: Amending the most recent commit message git commit --amend will open your editor, allowing you to change the commit message of the most recent commit. Additionally, you can set the commit message directly in the command line with: git commit --amend -m "New

Remove sensitive files and their commits from Git history

对着背影说爱祢 提交于 2019-11-25 23:56:44
问题 I would like to put a Git project on GitHub but it contains certain files with sensitive data (usernames and passwords, like /config/deploy.rb for capistrano). I know I can add these filenames to .gitignore , but this would not remove their history within Git. I also don\'t want to start over again by deleting the /.git directory. Is there a way to remove all traces of a particular file in your Git history? 回答1: For all practical purposes, the first thing you should be worried about is

How to change the commit author for one specific commit?

一笑奈何 提交于 2019-11-25 22:45:44
问题 I want to change the author of one specific commit in the history. It\'s not the last commit. I know about this question - How do I change the author of a commit in git? But I am thinking about something, where I identify the commit by hash or short-hash. 回答1: Interactive rebase off of a point earlier in the history than the commit you need to modify ( git rebase -i <earliercommit> ). In the list of commits being rebased, change the text from pick to edit next to the hash of the one you want

How can I remove a commit on GitHub? [duplicate]

我的梦境 提交于 2019-11-25 21:59:39
问题 This question already has answers here : Undoing a 'git push' (11 answers) Closed 3 months ago . I \"accidentally\" pushed a commit to GitHub. Is it possible to remove this commit? I want to revert my GitHub repository as it was before this commit. 回答1: Note: please see alternative to git rebase -i in the comments below— git reset --soft HEAD^ First, remove the commit on your local repository. You can do this using git rebase -i . For example, if it's your last commit, you can do git rebase

How do I undo the most recent local commits in Git?

落花浮王杯 提交于 2019-11-25 21:35:37
问题 I accidentally committed the wrong files to Git, but I haven\'t pushed the commit to the server yet. How can I undo those commits from the local repository? 回答1: Undo a commit and redo $ git commit -m "Something terribly misguided" # (1) $ git reset HEAD~ # (2) << edit files as necessary >> # (3) $ git add ... # (4) $ git commit -c ORIG_HEAD # (5) This is what you want to undo. This does nothing to your working tree (the state of your files on disk), but undoes the commit and leaves the

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

一笑奈何 提交于 2019-11-25 20:00:02
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