git-checkout

How can I reset or revert a file to a specific revision?

半腔热情 提交于 2019-11-27 05:33:44
I have made some changes to a file which has been committed a few times as part of a group of files, but now want to reset/revert the changes on it back to a previous version. I have done a git log along with a git diff to find the revision I need, but just have no idea how to get the file back to its former state in the past. Greg Hewgill Assuming the hash of the commit you want is c5f567 : git checkout c5f567 -- file1/to/restore file2/to/restore The git checkout man page gives more information. If you want to revert to the commit before c5f567 , append ~1 (works with any number): git

How can I reset or revert a file to a specific revision?

浪子不回头ぞ 提交于 2019-11-27 04:49:09
问题 I have made some changes to a file which has been committed a few times as part of a group of files, but now want to reset/revert the changes on it back to a previous version. I have done a git log along with a git diff to find the revision I need, but just have no idea how to get the file back to its former state in the past. 回答1: Assuming the hash of the commit you want is c5f567 : git checkout c5f567 -- file1/to/restore file2/to/restore The git checkout man page gives more information. If

Why does git checkout with explicit refs/heads/branch give detached HEAD?

纵然是瞬间 提交于 2019-11-27 02:38:48
问题 If I checkout a branch using just the branch name, HEAD is updated to point at that branch. $ git checkout branch Switched to branch 'branch' If I checkout a branch by using refs/heads/branch or heads/branch , HEAD becomes detached. $ git checkout refs/heads/branch Note: checking out 'refs/heads/branch'. You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by

git checkout error: unable to create file

大憨熊 提交于 2019-11-27 02:37:36
问题 While cloning a git repository from Linux to a Windows system, I am getting the following error in checkout the phase: $ git clone gituser@serveraddr:/git/git_repo.git git_WA Cloning into 'git_WA'... gituser@serveraddr's password: remote: Counting objects: 500846, done. remote: Compressing objects: 100% (118676/118676), done. remote: Total 500846 (delta 307739), reused 483023 (delta 291136) Receiving objects: 100% (500846/500846), 907.54 MiB | 9.04 MiB/s, done. Resolving deltas: 100% (307739

What is the difference between “git branch” and “git checkout -b”?

非 Y 不嫁゛ 提交于 2019-11-27 02:32:52
I used git checkout -b to create a new branch. I think that git branch does the same thing. How do these two commands differ, if they differ at all? Fatih git checkout -b BRANCH_NAME creates a new branch and checks out the new branch while git branch BRANCH_NAME creates a new branch but leaves you on the same branch. In other words git checkout -b BRANCH_NAME does the following for you. git branch BRANCH_NAME # create a new branch git checkout BRANCH_NAME # then switch to the new branch git branch creates the branch but you remain in the current branch that you have checked out. git checkout

Pulling just one directory out of a git repo

不羁的心 提交于 2019-11-27 01:57:16
问题 I have a git repo that I want to do a pull from. I do a normal git pull with no problems. The issue is that I want just one certain directory out of the repo. My thinking was that I could use a .gitignore file with a rule like this: #Ignore all files / #Except the one I want !/temp The problem is this doesn't work. Is that the right way to do it or is there a better way? 回答1: git pull fetches and merges the remote branch. .gitignore works only locally, and will hide matching entries from

Why does git-rebase give me merge conflicts when all I'm doing is squashing commits?

最后都变了- 提交于 2019-11-26 23:47:36
问题 We have a Git repository with over 400 commits, the first couple dozen of which were a lot of trial-and-error. We want to clean up these commits by squashing many down into a single commit. Naturally, git-rebase seems the way to go. My problem is that it ends up with merge conflicts, and these conflicts are not easy to resolve. I don't understand why there should be any conflicts at all, since I'm just squashing commits (not deleting or rearranging). Very likely, this demonstrates that I'm

Git push error: Unable to unlink old (Permission denied)

百般思念 提交于 2019-11-26 23:44:57
In the remote server I have a post-receive hook set up in order to make a git checkout of my repository: #!/bin/sh GIT_WORK_TREE=/var/www/<website> git checkout -f But when I make a push from my local machine to the git repository in the server, I get the following error messages: remote: error: unable to unlink old '<file>' (Permission denied) This appears many times over, one error message for almost every file. However I have a README.txt file that I'm able to change using git, here are its permissions: -rw-r--r-- 1 <serverusername> <serverusername> 2939 Aug 2 10:58 README.txt But other

switch git branch without files checkout

喜你入骨 提交于 2019-11-26 22:19:15
问题 Is it possible in git to switch to another branch without checking out all files? After switching branch I need to delete all files, regenerate them, commit and switch back. So checking out files is just a waste of times (and there are about 14000 files - it is a long operation). To make everything clear: I need all this to upload documentation to github. I have repo with gh-pages branch. When I rebuild documentation locally, I copy it to repo directory, commit and push to github. But I was

git: Switch branch and ignore any changes without committing

陌路散爱 提交于 2019-11-26 21:14:05
I was working on a git branch and was ready to commit my changes, so I made a commit with a useful commit message. I then absentmindedly made minor changes to the code that are not worth keeping. I now want to change branches, but git gives me, error: You have local changes to "X"; cannot switch branches. I thought that I could change branches without committing. If so, how can I set this up? If not, how do I get out of this problem? I want to ignore the minor changes without committing and just change branches. VonC You need a clean state to change branches. The branch checkout will only be