Git replacing LF with CRLF
2022-06-16
Question On a Windows machine, I added some files using git add. I got warnings saying: LF will be replaced by CRLF What are the ramifications of this conversion? Answer These messages are due to an incorrect default value of core.autocrlf on Windows. The concept of autocrlf is to handle line endings conversions transparently. And it does! Bad news: the value needs to be configured manually. Good news: it should only be done one time per Git installation (per project setting is also possible).…
How to find a deleted file in the project commit history?
2022-06-16
Question Once upon a time, there was a file in my project that I would now like to be able to get. The problem is: I have no idea of when have I deleted it and on which path it was. How can I locate the commits of this file when it existed? Answer If you do not know the exact path you may use git log --all --full-history -- "…
Throw away local commits in Git
2022-06-16
Question Due to some bad cherry-picking, my local Git repository is currently five commits ahead of the origin, and not in a good state. I want to get rid of all these commits and start over again. Obviously, deleting my working directory and re-cloning would do it, but downloading everything from GitHub again seems like overkill, and not a good use of my time. Maybe git revert is what I need, but I don't want to end up 10 commits ahead of the origin (or even six), even if it does get the code itself back to the right state.…
How to .gitignore all files/folder in a folder, but not the folder itself? [duplicate]
2022-06-15
Question This question already has answers here: </div> How do I add an empty directory to a Git repository? (37 answers) Closed 2 years ago. I want to check in a blank folder to my Git repository. Effectively, I need to ignore all of the files and folders within the folder, but not the folder itself. How can I do this? What should I put in my .gitignore file? For those wondering why I would want to do this, I have an "…
How do I clear my local working directory in Git? [duplicate]
2022-06-14
Question This question already has answers here: </div> How do I remove local (untracked) files from the current Git working tree? (41 answers) Closed 9 years ago. How can I clear my working directory in Git? Answer To reset a specific file to the last-committed state (to discard uncommitted changes in a specific file): git checkout thefiletoreset.txt This is mentioned in the git status output: (use "git checkout -- <file>..." to discard changes in working directory) To reset the entire repository to the last committed state:…
How to determine when a Git branch was created?
2022-06-14
Question Is there a way to determine when a Git branch was created? I have a branch in my repo and and I don't remember creating it and thought maybe seeing the creation timestamp would jog my memory. Answer As pointed out in the comments and in Jackub's answer, as long as your branch is younger than the number of days set in the config setting gc.reflogexpire (the default is 90 days), then you can utilize your reflog to find out when a branch reference was first created.…
How do I clone a single branch in Git?
2022-06-13
Question I have a local Git repository in ~/local_repo. It has a few branches: $ git branch * master rails c c++ To clone the local repository, I do: $ git clone ~/local_repo new_repo Initialized empty Git repository in /home/username/new_repo/.git/ The new_repo master branch points to the local_repo master branch, and I can push / pull. But I am unable to clone another branch. I want to only pull the branch I want (e.…