Make 'git diff' ignore ^M
2022-12-02
Question In a project where some of the files contain ^M as newline separators, diffing these files is apparently impossible, since git diff sees the entire file as just a single line. How does one git diff when comparing the current and previous versions of a source code file? Is there an option like "treat ^M as newline when diffing" ? prompt> git-diff "HEAD^" -- MyFile.as diff --git a/myproject/MyFile.as b/myproject/MyFile.as index be78321.…
Receiving "fatal: Not a git repository" when attempting to remote add a Git repo
2022-12-02
Question I am following this tutorial. Everything works fine until I run this on my local machine (after replacing the $VARIABLEs with their actual values): git remote add nfsn ssh://$USERNAME@$SERVER/home/private/git/$REPONAME.git I receive the following error message: fatal: Not a git repository (or any of the parent directories): .git How do I get past this step? Answer Did you init a local Git repository, into which this remote is supposed to be added?…
How to check whether a pandas DataFrame is empty?
2022-12-01
Question How to check whether a pandas DataFrame is empty? In my case I want to print some message in terminal if the DataFrame is empty. Answer You can use the attribute df.empty to check whether it's empty or not: if df.empty: print('DataFrame is empty!') Source: Pandas Documentation
Updating a local repository with changes from a GitHub repository
2022-12-01
Question I've got a project checked locally from GitHub, and that remote repository has since had changes made to it. What's the correct command to update my local copy with the latest changes? Answer Probably: was: git pull origin master now: git pull origin main
How can I switch to another branch in git?
2022-11-29
Question Which one of these lines is correct? git checkout 'another_branch' or git checkout origin 'another_branch' or git checkout origin/'another_branch' And what is the difference between them? Answer If another_branch already exists locally and you are not on this branch, then git checkout another_branch switches to the branch. If another_branch does not exist but origin/another_branch does, then git checkout another_branch is equivalent to git checkout -b another_branch origin/another_branch; git branch -u origin/another_branch.…
How do I delete a commit from a branch?
2022-11-29
Question How do I delete a commit from my branch history? Should I use git reset --hard HEAD? Answer Careful: git reset --hard WILL DELETE YOUR WORKING DIRECTORY CHANGES. Be sure to stash any local changes you want to keep before running this command. Assuming you are sitting on that commit, then this command will wack it... git reset --hard HEAD~1 The HEAD~1 means the commit before head. Or, you could look at the output of git log, find the commit id of the commit you want to back up to, and then do this:…
Forking vs. Branching in GitHub
2022-11-28
Question I'd like to know more about the advantages and disadvantages of forking a github project vs. creating a branch of a github project. Forking makes my version of the project more isolated from the original one because I don't have to be on the collaborators list of the original project. Since we're developing a project in house, there is no problem in adding people as collaborators. But, we'd like to understand if forking a project would make merge changes back to the main project harder.…