How do I squash two non-consecutive commits?
2022-02-19
Question I'm a bit new to the whole rebasing feature within git. Let's say that I made the following commits: A -> B -> C -> D Afterwards, I realize that D contains a fix which depends on some new code added in A, and that these commits belong together. How do I squash A & D together and leave B & C alone? Answer You can run git rebase --interactive and reorder D before B and squash D into A.…
How to apply unmerged upstream pull requests from other forks into my fork?
2022-02-19
Question A project on GitHub that I have a fork of has a new pull requests that I want to pull into my fork that the author has not pulled in yet. Is there a simple way to apply pull request from other forks into my fork? Is there something else here that I am missing? Answer Update: Via Webpage You can also do this via the github webpage. I assume, you should have already a fork (MyFork) of the common repo (BaseRepo) which has the pending pull request from a fork (OtherFork) you are interested in.…
Revert to a commit by a SHA hash in Git? [duplicate]
2022-02-19
Question This question already has answers here: </div> How do I revert a Git repository to a previous commit? (41 answers) Closed 9 years ago. I'm not clear on how git revert works. For example, I want to revert to a commit six commits behind the head, reverting all the changes in the intermediary commits in between. Say its SHA hash is 56e05fced214c44a37759efa2dfc25a65d8ae98d. Then why can't I just do something like:…
What does FETCH_HEAD in Git mean?
2022-02-19
Question git pull --help says: In its default mode, git pull is shorthand for git fetch followed by git merge FETCH_HEAD. What is this FETCH_HEAD and what is actually merged during git pull? Answer FETCH_HEAD is a short-lived ref, to keep track of what has just been fetched from the remote repository. git pull first invokes git fetch, in normal cases fetching a branch from the remote; FETCH_HEAD points to the tip of this branch (it stores the SHA1 of the commit, just as branches do).…
fetch from origin with deleted remote branches?
2022-02-18
Question When I do git fetch origin and origin has a deleted branch, it doesn't seem to update it in my repository. When I do git branch -r it still shows origin/DELETED_BRANCH. How can I fix this? Answer You need to do the following git fetch -p The -p or --prune argument will update the local database of remote branches.
How to apply a patch generated with git format-patch?
2022-02-18
Question I have two local git repositories, both pointing to the same remote repository. In one git repository, if I do git format-patch 1, how can I apply that patch to the other repository? Answer Note: You can first preview what your patch will do: First the stats: git apply --stat a_file.patch Then a dry run to detect errors: git apply --check a_file.patch Finally, you can use git am to apply your patch as a commit.…
How to delete rows from a pandas DataFrame based on a conditional expression [duplicate]
2022-02-18
Question This question already has answers here: </div> Deleting DataFrame row in Pandas based on column value (17 answers) Closed 3 years ago. I have a pandas DataFrame and I want to delete rows from it where the length of the string in a particular column is greater than 2. I expect to be able to do this (per this answer): df[(len(df['column name']) < 2)] but I just get the error:…