How can I view prior commits with git blame?
2022-05-25
Question Is it possible to see who edited a specific line before the commit reported by git blame, like a history of commits for a given line? For example, I run the following (on the superb uncrustify project): $ git blame -L10,+1 src/options.cpp ^fe25b6d (Ben Gardner 2009-10-17 13:13:55 -0500 10) #include "prototypes.h" How can I find out who edited that line before commit fe25b6d? And who edited it before that commit?…
How do I stash only one file out of multiple files that have changed?
2022-05-25
Question How do I stash only one of the multiple changed files on my branch? Answer git stash push -p -m "my commit message" -p let's you select the hunks that should be stashed; whole files can be selected as well. You'll be prompted with a few actions for each hunk: y - stash this hunk n - do not stash this hunk q - quit; do not stash this hunk or any of the remaining ones a - stash this hunk and all later hunks in the file d - do not stash this hunk or any of the later hunks in the file g - select a hunk to go to / - search for a hunk matching the given regex j - leave this hunk undecided, see next undecided hunk J - leave this hunk undecided, see next hunk k - leave this hunk undecided, see previous undecided hunk K - leave this hunk undecided, see previous hunk s - split the current hunk into smaller hunks e - manually edit the current hunk ?…
How can I push a specific commit to a remote, and not previous commits?
2022-05-24
Question I have made several commits on different files, but so far I would like to push to my remote repository only a specific commit. Is that possible? Answer To push up through a given commit, you can write: git push <remotename> <commit SHA>:<remotebranchname> provided <remotebranchname> already exists on the remote. (If it doesn't, you can use git push <remotename> <commit SHA>:refs/heads/<remotebranchname> to autocreate it.) If you want to push a commit without pushing previous commits, you should first use git rebase -i to re-order the commits.…
How do I push amended commit to the remote Git repository?
2022-05-23
Question 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.…
Is it safe to shallow clone with --depth 1, create commits, and pull updates again?
2022-05-23
Question The --depth 1 option in git clone: Create a shallow clone with a history truncated to the specified number of revisions. A shallow repository has a number of limitations (you cannot clone or fetch from it, nor push from nor into it), but is adequate if you are only interested in the recent history of a large project with a long history, and would want to send in fixes as patches.…
Writing a pandas DataFrame to CSV file
2022-05-23
Question I have a dataframe in pandas which I would like to write to a CSV file. I am doing this using: df.to_csv('out.csv') And getting the following error: UnicodeEncodeError: 'ascii' codec can't encode character u'\u03b1' in position 20: ordinal not in range(128) Is there any way to get around this easily (i.e. I have unicode characters in my data frame)? And is there a way to write to a tab delimited file instead of a CSV using e.…
How to change line-ending settings
2022-05-22
Question Is there a file or menu that will let me change the settings on how to deal with line endings? I read there are 3 options: Checkout Windows-style, commit Unix-style Git will convert LF to CRLF when checking out text files. When committing text files, CRLF will be converted to LF. For cross-platform projects, this is the recommended setting on Windows ("core.autocrlf" is set to "true") Checkout as-is, commit Unix-style…