How to merge remote master to local branch
2022-05-28
Question I have a local branch of a project ("configUpdate") that I've forked from somebody else's project and I've done a load of changes on it and would like to merge the changes they've made in to my local branch. I've tried git pull --rebase origin configUpdate but it hasn't grabbed the latest changes - how can I merge the two? (also for bonus points what did I do with the pull --rebase command?…
Get the short Git version hash
2022-05-27
Question Is there a cleaner way to get the short version hash of HEAD from Git? I want to see the same output as I get from: git log -n 1 | head -n 1 | sed -e 's/^commit //' | head -c 8 I originally used the above command to generate a version string, but this is even better: git describe --tags It will output strings like 0.1.12 (tagged commit) or 0.…
git stash changes apply to new branch?
2022-05-27
Question I was working on master branch, made some changes and then stashed them. Now, my master is at HEAD. But now, I want to retrieve these changes but to a new branch which branches from the HEAD version of the master branch. How do i do this ? Answer Is the standard procedure not working? make changes git stash save git branch xxx HEAD git checkout xxx git stash pop Shorter:…
How do I undo 'git add' before commit?
2022-05-27
Question Want to improve this post? Provide detailed answers to this question, including citations and an explanation of why your answer is correct. Answers without enough detail may be edited or deleted. </div> I mistakenly added files to Git using the command: git add myfile.txt I have not yet run git commit. How do I undo this so that these changes will not be included in the commit? Answer Undo git add for uncommitted changes with:…
Move the most recent commit(s) to a new branch with Git
2022-05-27
Question How do I move my recent commits on master to a new branch, and reset master to before those commits were made? e.g. From this: master A - B - C - D - E To this: newbranch C - D - E / master A - B Answer Moving to an existing branch If you want to move your commits to an existing branch, it will look like this:…
git: undo all working dir changes including new files
2022-05-26
Question How to delete all changes from working directory including new untracked files. I know that git checkout -f does that, but it doesn't delete new untracked files created since last commit. Does anybody have an idea how to do that? Answer git reset --hard # removes staged and working directory changes !! be very careful with these !! you may end up deleting what you don’t want to read comments and manual.…
.gitignore after commit [duplicate]
2022-05-25
Question This question already has answers here: </div> How do I make Git forget about a file that was tracked, but is now in .gitignore? (33 answers) Closed 2 years ago. I have a git repository hosted on Github. After committing many files, I am realizing that I need to create .gitignore and exclude .exe, .obj files. However, will it automatically remove these committed files from the repository? Is there any way to force that?…